2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $FreeBSD: src/lib/msun/src/math_private.h,v 1.20 2005/11/28 04:58:57 bde Exp $
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
21 #include <sys/types.h>
22 #include <machine/endian.h>
24 #include <aros/system.h>
29 * The original fdlibm code used statements like:
30 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
31 * ix0 = *(n0+(int*)&x); * high word of x *
32 * ix1 = *((1-n0)+(int*)&x); * low word of x *
33 * to dig two 32 bit words out of the 64 bit IEEE floating point
34 * value. That is non-ANSI, and, moreover, the gcc instruction
35 * scheduler gets it wrong. We instead use the following macros.
36 * Unlike the original code, we determine the endianness at compile
37 * time, not at run time; I don't see much benefit to selecting
38 * endianness at run time.
42 * A union which permits us to convert between a double and two 32 bit
56 } ieee_double_shape_type
;
70 } ieee_double_shape_type
;
74 /* Get two 32 bit ints from a double. */
76 #define EXTRACT_WORDS(ix0,ix1,d) \
78 ieee_double_shape_type ew_u; \
80 (ix0) = ew_u.parts.msw; \
81 (ix1) = ew_u.parts.lsw; \
84 /* Get the more significant 32 bit int from a double. */
86 #define GET_HIGH_WORD(i,d) \
88 ieee_double_shape_type gh_u; \
90 (i) = gh_u.parts.msw; \
93 /* Get the less significant 32 bit int from a double. */
95 #define GET_LOW_WORD(i,d) \
97 ieee_double_shape_type gl_u; \
99 (i) = gl_u.parts.lsw; \
102 /* Set a double from two 32 bit ints. */
104 #define INSERT_WORDS(d,ix0,ix1) \
106 ieee_double_shape_type iw_u; \
107 iw_u.parts.msw = (ix0); \
108 iw_u.parts.lsw = (ix1); \
112 /* Set the more significant 32 bits of a double from an int. */
114 #define SET_HIGH_WORD(d,v) \
116 ieee_double_shape_type sh_u; \
118 sh_u.parts.msw = (v); \
122 /* Set the less significant 32 bits of a double from an int. */
124 #define SET_LOW_WORD(d,v) \
126 ieee_double_shape_type sl_u; \
128 sl_u.parts.lsw = (v); \
133 * A union which permits us to convert between a float and a 32 bit
140 /* FIXME: Assumes 32 bit int. */
142 } ieee_float_shape_type
;
144 /* Get a 32 bit int from a float. */
146 #define GET_FLOAT_WORD(i,d) \
148 ieee_float_shape_type gf_u; \
153 /* Set a float from a 32 bit int. */
155 #define SET_FLOAT_WORD(d,i) \
157 ieee_float_shape_type sf_u; \
164 * Inline functions that can be used to construct complex values.
166 * The C99 standard intends x+I*y to be used for this, but x+I*y is
167 * currently unusable in general since gcc introduces many overflow,
168 * underflow, sign and efficiency bugs by rewriting I*y as
169 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
170 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
173 static __inline
float complex
174 cpackf(float x
, float y
)
183 static __inline
double complex
184 cpack(double x
, double y
)
193 static __inline
long double complex
194 cpackl(long double x
, long double y
)
196 long double complex z
;
202 #endif /* _COMPLEX_H */
205 * ieee style elementary functions
207 * We rename functions here to improve other sources' diffability
210 #define __ieee754_sqrt sqrt
211 #define __ieee754_acos acos
212 #define __ieee754_acosh acosh
213 #define __ieee754_log log
214 #define __ieee754_atanh atanh
215 #define __ieee754_asin asin
216 #define __ieee754_atan2 atan2
217 #define __ieee754_exp exp
218 #define __ieee754_cosh cosh
219 #define __ieee754_fmod fmod
220 #define __ieee754_pow pow
221 #define __ieee754_lgamma lgamma
222 #define __ieee754_gamma gamma
223 #define __ieee754_lgamma_r lgamma_r
224 #define __ieee754_gamma_r gamma_r
225 #define __ieee754_log10 log10
226 #define __ieee754_sinh sinh
227 #define __ieee754_hypot hypot
228 #define __ieee754_j0 j0
229 #define __ieee754_j1 j1
230 #define __ieee754_y0 y0
231 #define __ieee754_y1 y1
232 #define __ieee754_jn jn
233 #define __ieee754_yn yn
234 #define __ieee754_remainder remainder
235 #define __ieee754_scalb scalb
236 #define __ieee754_sqrtf sqrtf
237 #define __ieee754_acosf acosf
238 #define __ieee754_acoshf acoshf
239 #define __ieee754_logf logf
240 #define __ieee754_atanhf atanhf
241 #define __ieee754_asinf asinf
242 #define __ieee754_atan2f atan2f
243 #define __ieee754_expf expf
244 #define __ieee754_coshf coshf
245 #define __ieee754_fmodf fmodf
246 #define __ieee754_powf powf
247 #define __ieee754_lgammaf lgammaf
248 #define __ieee754_gammaf gammaf
249 #define __ieee754_lgammaf_r lgammaf_r
250 #define __ieee754_gammaf_r gammaf_r
251 #define __ieee754_log10f log10f
252 #define __ieee754_sinhf sinhf
253 #define __ieee754_hypotf hypotf
254 #define __ieee754_j0f j0f
255 #define __ieee754_j1f j1f
256 #define __ieee754_y0f y0f
257 #define __ieee754_y1f y1f
258 #define __ieee754_jnf jnf
259 #define __ieee754_ynf ynf
260 #define __ieee754_remainderf remainderf
261 #define __ieee754_scalbf scalbf
263 /* Under FreeBSD, int32_t and int are the same thing. On AROS it may not be,
264 * which causes the build to fail. This is a FreeBSD bug (prototypes don't
265 * match the functions proper), so we work around it with defines below. */
267 /* fdlibm kernel function */
268 #ifndef INLINE_REM_PIO2
270 int __ieee754_rem_pio2(double,double*);
272 int32_t __ieee754_rem_pio2(double,double*);
275 double __kernel_sin(double,double,int);
276 double __kernel_cos(double,double);
277 double __kernel_tan(double,double,int);
279 int __kernel_rem_pio2(double*,double*,int,int,int,const int*);
281 int __kernel_rem_pio2(double*,double*,int,int,int,const int32_t*);
284 /* float versions of fdlibm kernel functions */
285 #ifndef INLINE_REM_PIO2F
287 int __ieee754_rem_pio2f(float,float*);
289 int32_t __ieee754_rem_pio2f(float,float*);
292 #ifndef INLINE_KERNEL_SINDF
293 float __kernel_sindf(double);
295 #ifndef INLINE_KERNEL_COSDF
296 float __kernel_cosdf(double);
298 #ifndef INLINE_KERNEL_TANDF
299 float __kernel_tandf(double,int);
302 int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
304 int __kernel_rem_pio2f(float*,float*,int,int,int,const int32_t*);
307 #endif /* !_MATH_PRIVATE_H_ */