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
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include <machine/endian.h>
21 #include <sys/types.h>
23 /* The original fdlibm code used statements like:
24 n0 = ((*(int*)&one)>>29)^1; * index of high word *
25 ix0 = *(n0+(int*)&x); * high word of x *
26 ix1 = *((1-n0)+(int*)&x); * low word of x *
27 to dig two 32 bit words out of the 64 bit IEEE floating point
28 value. That is non-ANSI, and, moreover, the gcc instruction
29 scheduler gets it wrong. We instead use the following macros.
30 Unlike the original code, we determine the endianness at compile
31 time, not at run time; I don't see much benefit to selecting
32 endianness at run time. */
34 /* A union which permits us to convert between a double and two 32 bit
37 #if BYTE_ORDER == BIG_ENDIAN
47 } ieee_double_shape_type
;
51 #if BYTE_ORDER == LITTLE_ENDIAN
61 } ieee_double_shape_type
;
65 /* Get two 32 bit ints from a double. */
67 #define EXTRACT_WORDS(ix0,ix1,d) \
69 ieee_double_shape_type ew_u; \
71 (ix0) = ew_u.parts.msw; \
72 (ix1) = ew_u.parts.lsw; \
75 /* Get the more significant 32 bit int from a double. */
77 #define GET_HIGH_WORD(i,d) \
79 ieee_double_shape_type gh_u; \
81 (i) = gh_u.parts.msw; \
84 /* Get the less significant 32 bit int from a double. */
86 #define GET_LOW_WORD(i,d) \
88 ieee_double_shape_type gl_u; \
90 (i) = gl_u.parts.lsw; \
93 /* Set a double from two 32 bit ints. */
95 #define INSERT_WORDS(d,ix0,ix1) \
97 ieee_double_shape_type iw_u; \
98 iw_u.parts.msw = (ix0); \
99 iw_u.parts.lsw = (ix1); \
103 /* Set the more significant 32 bits of a double from an int. */
105 #define SET_HIGH_WORD(d,v) \
107 ieee_double_shape_type sh_u; \
109 sh_u.parts.msw = (v); \
113 /* Set the less significant 32 bits of a double from an int. */
115 #define SET_LOW_WORD(d,v) \
117 ieee_double_shape_type sl_u; \
119 sl_u.parts.lsw = (v); \
123 /* A union which permits us to convert between a float and a 32 bit
130 } ieee_float_shape_type
;
132 /* Get a 32 bit int from a float. */
134 #define GET_FLOAT_WORD(i,d) \
136 ieee_float_shape_type gf_u; \
141 /* Set a float from a 32 bit int. */
143 #define SET_FLOAT_WORD(d,i) \
145 ieee_float_shape_type sf_u; \
150 /* A union which permits us to convert between a long double and
151 three 32 bit ints. */
153 #if BYTE_ORDER == BIG_ENDIAN
160 unsigned int sign_exponent
:16;
161 unsigned int empty
:16;
165 } ieee_long_double_shape_type
;
169 #if BYTE_ORDER == LITTLE_ENDIAN
178 unsigned int sign_exponent
:16;
179 unsigned int empty
:16;
181 } ieee_long_double_shape_type
;
185 /* Get three 32 bit ints from a double. */
187 #define GET_LDOUBLE_WORDS(exp,ix0,ix1,d) \
189 ieee_long_double_shape_type ew_u; \
191 (exp) = ew_u.parts.sign_exponent; \
192 (ix0) = ew_u.parts.msw; \
193 (ix1) = ew_u.parts.lsw; \
196 /* Set a double from two 32 bit ints. */
198 #define SET_LDOUBLE_WORDS(d,exp,ix0,ix1) \
200 ieee_long_double_shape_type iw_u; \
201 iw_u.parts.sign_exponent = (exp); \
202 iw_u.parts.msw = (ix0); \
203 iw_u.parts.lsw = (ix1); \
207 /* Get the more significant 32 bits of a long double mantissa. */
209 #define GET_LDOUBLE_MSW(v,d) \
211 ieee_long_double_shape_type sh_u; \
213 (v) = sh_u.parts.msw; \
216 /* Set the more significant 32 bits of a long double mantissa from an int. */
218 #define SET_LDOUBLE_MSW(d,v) \
220 ieee_long_double_shape_type sh_u; \
222 sh_u.parts.msw = (v); \
226 /* Get int from the exponent of a long double. */
228 #define GET_LDOUBLE_EXP(exp,d) \
230 ieee_long_double_shape_type ge_u; \
232 (exp) = ge_u.parts.sign_exponent; \
235 /* Set exponent of a long double from an int. */
237 #define SET_LDOUBLE_EXP(d,exp) \
239 ieee_long_double_shape_type se_u; \
241 se_u.parts.sign_exponent = (exp); \
246 /* ieee style elementary functions */
247 extern double __ieee754_sqrt
__P((double));
248 extern double __ieee754_acos
__P((double));
249 extern double __ieee754_acosh
__P((double));
250 extern double __ieee754_log
__P((double));
251 extern double __ieee754_atanh
__P((double));
252 extern double __ieee754_asin
__P((double));
253 extern double __ieee754_atan2
__P((double,double));
254 extern double __ieee754_exp
__P((double));
255 extern double __ieee754_exp2
__P((double));
256 extern double __ieee754_cosh
__P((double));
257 extern double __ieee754_fmod
__P((double,double));
258 extern double __ieee754_pow
__P((double,double));
259 extern double __ieee754_lgamma_r
__P((double,int *));
260 extern double __ieee754_gamma_r
__P((double,int *));
261 extern double __ieee754_lgamma
__P((double));
262 extern double __ieee754_gamma
__P((double));
263 extern double __ieee754_log10
__P((double));
264 extern double __ieee754_sinh
__P((double));
265 extern double __ieee754_hypot
__P((double,double));
266 extern double __ieee754_j0
__P((double));
267 extern double __ieee754_j1
__P((double));
268 extern double __ieee754_y0
__P((double));
269 extern double __ieee754_y1
__P((double));
270 extern double __ieee754_jn
__P((int,double));
271 extern double __ieee754_yn
__P((int,double));
272 extern double __ieee754_remainder
__P((double,double));
273 extern int32_t __ieee754_rem_pio2
__P((double,double*));
274 extern double __ieee754_scalb
__P((double,double));
276 /* fdlibm kernel function */
277 extern double __kernel_standard
__P((double,double,int));
278 extern double __kernel_sin
__P((double,double,int));
279 extern double __kernel_cos
__P((double,double));
280 extern double __kernel_tan
__P((double,double,int));
281 extern int __kernel_rem_pio2
__P((double*,double*,int,int,int,
285 /* ieee style elementary float functions */
286 extern float __ieee754_sqrtf
__P((float));
287 extern float __ieee754_acosf
__P((float));
288 extern float __ieee754_acoshf
__P((float));
289 extern float __ieee754_logf
__P((float));
290 extern float __ieee754_atanhf
__P((float));
291 extern float __ieee754_asinf
__P((float));
292 extern float __ieee754_atan2f
__P((float,float));
293 extern float __ieee754_expf
__P((float));
294 extern float __ieee754_exp2f
__P((float));
295 extern float __ieee754_coshf
__P((float));
296 extern float __ieee754_fmodf
__P((float,float));
297 extern float __ieee754_powf
__P((float,float));
298 extern float __ieee754_lgammaf_r
__P((float,int *));
299 extern float __ieee754_gammaf_r
__P((float,int *));
300 extern float __ieee754_lgammaf
__P((float));
301 extern float __ieee754_gammaf
__P((float));
302 extern float __ieee754_log10f
__P((float));
303 extern float __ieee754_sinhf
__P((float));
304 extern float __ieee754_hypotf
__P((float,float));
305 extern float __ieee754_j0f
__P((float));
306 extern float __ieee754_j1f
__P((float));
307 extern float __ieee754_y0f
__P((float));
308 extern float __ieee754_y1f
__P((float));
309 extern float __ieee754_jnf
__P((int,float));
310 extern float __ieee754_ynf
__P((int,float));
311 extern float __ieee754_remainderf
__P((float,float));
312 extern int32_t __ieee754_rem_pio2f
__P((float,float*));
313 extern float __ieee754_scalbf
__P((float,float));
315 /* float versions of fdlibm kernel functions */
316 extern float __kernel_sinf
__P((float,float,int));
317 extern float __kernel_cosf
__P((float,float));
318 extern float __kernel_tanf
__P((float,float,int));
319 extern int __kernel_rem_pio2f
__P((float*,float*,int,int,int,
323 /* ieee style elementary long double functions */
324 extern long double __ieee754_sqrtl
__P((long double));
325 extern long double __ieee754_acosl
__P((long double));
326 extern long double __ieee754_acoshl
__P((long double));
327 extern long double __ieee754_logl
__P((long double));
328 extern long double __ieee754_atanhl
__P((long double));
329 extern long double __ieee754_asinl
__P((long double));
330 extern long double __ieee754_atan2l
__P((long double,long double));
331 extern long double __ieee754_expl
__P((long double));
332 extern long double __ieee754_exp2l
__P((long double));
333 extern long double __ieee754_coshl
__P((long double));
334 extern long double __ieee754_fmodl
__P((long double,long double));
335 extern long double __ieee754_powl
__P((long double,long double));
336 extern long double __ieee754_lgammal_r
__P((long double,int *));
337 extern long double __ieee754_gammal_r
__P((long double,int *));
338 extern long double __ieee754_lgammal
__P((long double));
339 extern long double __ieee754_gammal
__P((long double));
340 extern long double __ieee754_log10l
__P((long double));
341 extern long double __ieee754_sinhl
__P((long double));
342 extern long double __ieee754_hypotl
__P((long double,long double));
343 extern long double __ieee754_j0l
__P((long double));
344 extern long double __ieee754_j1l
__P((long double));
345 extern long double __ieee754_y0l
__P((long double));
346 extern long double __ieee754_y1l
__P((long double));
347 extern long double __ieee754_jnl
__P((int,long double));
348 extern long double __ieee754_ynl
__P((int,long double));
349 extern long double __ieee754_remainderl
__P((long double,long double));
350 extern int __ieee754_rem_pio2l
__P((long double,long double*));
351 extern long double __ieee754_scalbl
__P((long double,long double));
353 /* long double versions of fdlibm kernel functions */
354 extern long double __kernel_sinl
__P((long double,long double,int));
355 extern long double __kernel_cosl
__P((long double,long double));
356 extern long double __kernel_tanl
__P((long double,long double,int));
357 extern int __kernel_rem_pio2l
__P((long double*,long double*,int,int,
360 #endif /* _MATH_PRIVATE_H_ */