15af32e75SAxel Dörfler /* 25af32e75SAxel Dörfler * ==================================================== 35af32e75SAxel Dörfler * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 45af32e75SAxel Dörfler * 55af32e75SAxel Dörfler * Developed at SunPro, a Sun Microsystems, Inc. business. 65af32e75SAxel Dörfler * Permission to use, copy, modify, and distribute this 75af32e75SAxel Dörfler * software is freely granted, provided that this notice 85af32e75SAxel Dörfler * is preserved. 95af32e75SAxel Dörfler * ==================================================== 105af32e75SAxel Dörfler */ 115af32e75SAxel Dörfler 125af32e75SAxel Dörfler /* 135af32e75SAxel Dörfler * from: @(#)fdlibm.h 5.1 93/09/24 14571d840aSOliver Tappe * $Id: math_private.h 14968 2005-11-16 18:33:51Z korli $ 155af32e75SAxel Dörfler */ 165af32e75SAxel Dörfler 175af32e75SAxel Dörfler #ifndef _MATH_PRIVATE_H_ 185af32e75SAxel Dörfler #define _MATH_PRIVATE_H_ 195af32e75SAxel Dörfler 205af32e75SAxel Dörfler #include <endian.h> 215af32e75SAxel Dörfler #include <sys/types.h> 225af32e75SAxel Dörfler #include <stdint.h> 235af32e75SAxel Dörfler 24*aee48751SAugustin Cavalier #ifndef __FLOAT_WORD_ORDER 25*aee48751SAugustin Cavalier #define __FLOAT_WORD_ORDER __BYTE_ORDER 26*aee48751SAugustin Cavalier #endif 27*aee48751SAugustin Cavalier 285af32e75SAxel Dörfler /* The original fdlibm code used statements like: 295af32e75SAxel Dörfler n0 = ((*(int*)&one)>>29)^1; * index of high word * 305af32e75SAxel Dörfler ix0 = *(n0+(int*)&x); * high word of x * 315af32e75SAxel Dörfler ix1 = *((1-n0)+(int*)&x); * low word of x * 325af32e75SAxel Dörfler to dig two 32 bit words out of the 64 bit IEEE floating point 335af32e75SAxel Dörfler value. That is non-ANSI, and, moreover, the gcc instruction 345af32e75SAxel Dörfler scheduler gets it wrong. We instead use the following macros. 355af32e75SAxel Dörfler Unlike the original code, we determine the endianness at compile 365af32e75SAxel Dörfler time, not at run time; I don't see much benefit to selecting 375af32e75SAxel Dörfler endianness at run time. */ 385af32e75SAxel Dörfler 395af32e75SAxel Dörfler /* A union which permits us to convert between a double and two 32 bit 405af32e75SAxel Dörfler ints. */ 415af32e75SAxel Dörfler 425af32e75SAxel Dörfler #if __FLOAT_WORD_ORDER == BIG_ENDIAN 435af32e75SAxel Dörfler 445af32e75SAxel Dörfler typedef union 455af32e75SAxel Dörfler { 465af32e75SAxel Dörfler double value; 475af32e75SAxel Dörfler struct 485af32e75SAxel Dörfler { 495af32e75SAxel Dörfler u_int32_t msw; 505af32e75SAxel Dörfler u_int32_t lsw; 515af32e75SAxel Dörfler } parts; 525af32e75SAxel Dörfler } ieee_double_shape_type; 535af32e75SAxel Dörfler 545af32e75SAxel Dörfler #endif 555af32e75SAxel Dörfler 565af32e75SAxel Dörfler #if __FLOAT_WORD_ORDER == LITTLE_ENDIAN 575af32e75SAxel Dörfler 585af32e75SAxel Dörfler typedef union 595af32e75SAxel Dörfler { 605af32e75SAxel Dörfler double value; 615af32e75SAxel Dörfler struct 625af32e75SAxel Dörfler { 635af32e75SAxel Dörfler u_int32_t lsw; 645af32e75SAxel Dörfler u_int32_t msw; 655af32e75SAxel Dörfler } parts; 665af32e75SAxel Dörfler } ieee_double_shape_type; 675af32e75SAxel Dörfler 685af32e75SAxel Dörfler #endif 695af32e75SAxel Dörfler 705af32e75SAxel Dörfler /* Get two 32 bit ints from a double. */ 715af32e75SAxel Dörfler 725af32e75SAxel Dörfler #define EXTRACT_WORDS(ix0,ix1,d) \ 735af32e75SAxel Dörfler do { \ 745af32e75SAxel Dörfler ieee_double_shape_type ew_u; \ 755af32e75SAxel Dörfler ew_u.value = (d); \ 765af32e75SAxel Dörfler (ix0) = ew_u.parts.msw; \ 775af32e75SAxel Dörfler (ix1) = ew_u.parts.lsw; \ 785af32e75SAxel Dörfler } while (0) 795af32e75SAxel Dörfler 805af32e75SAxel Dörfler /* Get the more significant 32 bit int from a double. */ 815af32e75SAxel Dörfler 825af32e75SAxel Dörfler #define GET_HIGH_WORD(i,d) \ 835af32e75SAxel Dörfler do { \ 845af32e75SAxel Dörfler ieee_double_shape_type gh_u; \ 855af32e75SAxel Dörfler gh_u.value = (d); \ 865af32e75SAxel Dörfler (i) = gh_u.parts.msw; \ 875af32e75SAxel Dörfler } while (0) 885af32e75SAxel Dörfler 895af32e75SAxel Dörfler /* Get the less significant 32 bit int from a double. */ 905af32e75SAxel Dörfler 915af32e75SAxel Dörfler #define GET_LOW_WORD(i,d) \ 925af32e75SAxel Dörfler do { \ 935af32e75SAxel Dörfler ieee_double_shape_type gl_u; \ 945af32e75SAxel Dörfler gl_u.value = (d); \ 955af32e75SAxel Dörfler (i) = gl_u.parts.lsw; \ 965af32e75SAxel Dörfler } while (0) 975af32e75SAxel Dörfler 985af32e75SAxel Dörfler /* Set a double from two 32 bit ints. */ 995af32e75SAxel Dörfler 1005af32e75SAxel Dörfler #define INSERT_WORDS(d,ix0,ix1) \ 1015af32e75SAxel Dörfler do { \ 1025af32e75SAxel Dörfler ieee_double_shape_type iw_u; \ 1035af32e75SAxel Dörfler iw_u.parts.msw = (ix0); \ 1045af32e75SAxel Dörfler iw_u.parts.lsw = (ix1); \ 1055af32e75SAxel Dörfler (d) = iw_u.value; \ 1065af32e75SAxel Dörfler } while (0) 1075af32e75SAxel Dörfler 1085af32e75SAxel Dörfler /* Set the more significant 32 bits of a double from an int. */ 1095af32e75SAxel Dörfler 1105af32e75SAxel Dörfler #define SET_HIGH_WORD(d,v) \ 1115af32e75SAxel Dörfler do { \ 1125af32e75SAxel Dörfler ieee_double_shape_type sh_u; \ 1135af32e75SAxel Dörfler sh_u.value = (d); \ 1145af32e75SAxel Dörfler sh_u.parts.msw = (v); \ 1155af32e75SAxel Dörfler (d) = sh_u.value; \ 1165af32e75SAxel Dörfler } while (0) 1175af32e75SAxel Dörfler 1185af32e75SAxel Dörfler /* Set the less significant 32 bits of a double from an int. */ 1195af32e75SAxel Dörfler 1205af32e75SAxel Dörfler #define SET_LOW_WORD(d,v) \ 1215af32e75SAxel Dörfler do { \ 1225af32e75SAxel Dörfler ieee_double_shape_type sl_u; \ 1235af32e75SAxel Dörfler sl_u.value = (d); \ 1245af32e75SAxel Dörfler sl_u.parts.lsw = (v); \ 1255af32e75SAxel Dörfler (d) = sl_u.value; \ 1265af32e75SAxel Dörfler } while (0) 1275af32e75SAxel Dörfler 1285af32e75SAxel Dörfler /* A union which permits us to convert between a float and a 32 bit 1295af32e75SAxel Dörfler int. */ 1305af32e75SAxel Dörfler 1315af32e75SAxel Dörfler typedef union 1325af32e75SAxel Dörfler { 1335af32e75SAxel Dörfler float value; 1345af32e75SAxel Dörfler u_int32_t word; 1355af32e75SAxel Dörfler } ieee_float_shape_type; 1365af32e75SAxel Dörfler 1375af32e75SAxel Dörfler /* Get a 32 bit int from a float. */ 1385af32e75SAxel Dörfler 1395af32e75SAxel Dörfler #define GET_FLOAT_WORD(i,d) \ 1405af32e75SAxel Dörfler do { \ 1415af32e75SAxel Dörfler ieee_float_shape_type gf_u; \ 1425af32e75SAxel Dörfler gf_u.value = (d); \ 1435af32e75SAxel Dörfler (i) = gf_u.word; \ 1445af32e75SAxel Dörfler } while (0) 1455af32e75SAxel Dörfler 1465af32e75SAxel Dörfler /* Set a float from a 32 bit int. */ 1475af32e75SAxel Dörfler 1485af32e75SAxel Dörfler #define SET_FLOAT_WORD(d,i) \ 1495af32e75SAxel Dörfler do { \ 1505af32e75SAxel Dörfler ieee_float_shape_type sf_u; \ 1515af32e75SAxel Dörfler sf_u.word = (i); \ 1525af32e75SAxel Dörfler (d) = sf_u.value; \ 1535af32e75SAxel Dörfler } while (0) 1545af32e75SAxel Dörfler 1555af32e75SAxel Dörfler /* Get long double macros from a separate header. */ 1565412911fSJérôme Duval #include <math_ldbl.h> 1575af32e75SAxel Dörfler 1585af32e75SAxel Dörfler /* ieee style elementary functions */ 1595af32e75SAxel Dörfler extern double __ieee754_sqrt (double); 1605af32e75SAxel Dörfler extern double __ieee754_acos (double); 1615af32e75SAxel Dörfler extern double __ieee754_acosh (double); 1625af32e75SAxel Dörfler extern double __ieee754_log (double); 1635af32e75SAxel Dörfler extern double __ieee754_atanh (double); 1645af32e75SAxel Dörfler extern double __ieee754_asin (double); 1655af32e75SAxel Dörfler extern double __ieee754_atan2 (double,double); 1665af32e75SAxel Dörfler extern double __ieee754_exp (double); 1675af32e75SAxel Dörfler extern double __ieee754_exp2 (double); 1685af32e75SAxel Dörfler extern double __ieee754_exp10 (double); 1695af32e75SAxel Dörfler extern double __ieee754_cosh (double); 1705af32e75SAxel Dörfler extern double __ieee754_fmod (double,double); 1715af32e75SAxel Dörfler extern double __ieee754_pow (double,double); 1725af32e75SAxel Dörfler extern double __ieee754_lgamma_r (double,int *); 1735af32e75SAxel Dörfler extern double __ieee754_gamma_r (double,int *); 1745af32e75SAxel Dörfler extern double __ieee754_lgamma (double); 1755af32e75SAxel Dörfler extern double __ieee754_gamma (double); 1765af32e75SAxel Dörfler extern double __ieee754_log10 (double); 1775af32e75SAxel Dörfler extern double __ieee754_log2 (double); 1785af32e75SAxel Dörfler extern double __ieee754_sinh (double); 1795af32e75SAxel Dörfler extern double __ieee754_hypot (double,double); 1805af32e75SAxel Dörfler extern double __ieee754_j0 (double); 1815af32e75SAxel Dörfler extern double __ieee754_j1 (double); 1825af32e75SAxel Dörfler extern double __ieee754_y0 (double); 1835af32e75SAxel Dörfler extern double __ieee754_y1 (double); 1845af32e75SAxel Dörfler extern double __ieee754_jn (int,double); 1855af32e75SAxel Dörfler extern double __ieee754_yn (int,double); 1865af32e75SAxel Dörfler extern double __ieee754_remainder (double,double); 1875af32e75SAxel Dörfler extern int32_t __ieee754_rem_pio2 (double,double*); 1885af32e75SAxel Dörfler extern double __ieee754_scalb (double,double); 1895af32e75SAxel Dörfler 1905af32e75SAxel Dörfler /* fdlibm kernel function */ 1915af32e75SAxel Dörfler extern double __kernel_standard (double,double,int); 1925af32e75SAxel Dörfler extern double __kernel_sin (double,double,int); 1935af32e75SAxel Dörfler extern double __kernel_cos (double,double); 1945af32e75SAxel Dörfler extern double __kernel_tan (double,double,int); 1955af32e75SAxel Dörfler extern int __kernel_rem_pio2 (double*,double*,int,int,int, const int32_t*); 1965af32e75SAxel Dörfler 1975af32e75SAxel Dörfler /* internal functions. */ 1985af32e75SAxel Dörfler extern double __copysign (double x, double __y); 1995af32e75SAxel Dörfler 2005af32e75SAxel Dörfler 2015af32e75SAxel Dörfler /* ieee style elementary float functions */ 2025af32e75SAxel Dörfler extern float __ieee754_sqrtf (float); 2035af32e75SAxel Dörfler extern float __ieee754_acosf (float); 2045af32e75SAxel Dörfler extern float __ieee754_acoshf (float); 2055af32e75SAxel Dörfler extern float __ieee754_logf (float); 2065af32e75SAxel Dörfler extern float __ieee754_atanhf (float); 2075af32e75SAxel Dörfler extern float __ieee754_asinf (float); 2085af32e75SAxel Dörfler extern float __ieee754_atan2f (float,float); 2095af32e75SAxel Dörfler extern float __ieee754_expf (float); 2105af32e75SAxel Dörfler extern float __ieee754_exp2f (float); 2115af32e75SAxel Dörfler extern float __ieee754_exp10f (float); 2125af32e75SAxel Dörfler extern float __ieee754_coshf (float); 2135af32e75SAxel Dörfler extern float __ieee754_fmodf (float,float); 2145af32e75SAxel Dörfler extern float __ieee754_powf (float,float); 2155af32e75SAxel Dörfler extern float __ieee754_lgammaf_r (float,int *); 2165af32e75SAxel Dörfler extern float __ieee754_gammaf_r (float,int *); 2175af32e75SAxel Dörfler extern float __ieee754_lgammaf (float); 2185af32e75SAxel Dörfler extern float __ieee754_gammaf (float); 2195af32e75SAxel Dörfler extern float __ieee754_log10f (float); 2205af32e75SAxel Dörfler extern float __ieee754_log2f (float); 2215af32e75SAxel Dörfler extern float __ieee754_sinhf (float); 2225af32e75SAxel Dörfler extern float __ieee754_hypotf (float,float); 2235af32e75SAxel Dörfler extern float __ieee754_j0f (float); 2245af32e75SAxel Dörfler extern float __ieee754_j1f (float); 2255af32e75SAxel Dörfler extern float __ieee754_y0f (float); 2265af32e75SAxel Dörfler extern float __ieee754_y1f (float); 2275af32e75SAxel Dörfler extern float __ieee754_jnf (int,float); 2285af32e75SAxel Dörfler extern float __ieee754_ynf (int,float); 2295af32e75SAxel Dörfler extern float __ieee754_remainderf (float,float); 2305af32e75SAxel Dörfler extern int32_t __ieee754_rem_pio2f (float,float*); 2315af32e75SAxel Dörfler extern float __ieee754_scalbf (float,float); 2325af32e75SAxel Dörfler 2335af32e75SAxel Dörfler 2345af32e75SAxel Dörfler /* float versions of fdlibm kernel functions */ 2355af32e75SAxel Dörfler extern float __kernel_sinf (float,float,int); 2365af32e75SAxel Dörfler extern float __kernel_cosf (float,float); 2375af32e75SAxel Dörfler extern float __kernel_tanf (float,float,int); 2385af32e75SAxel Dörfler extern int __kernel_rem_pio2f (float*,float*,int,int,int, const int32_t*); 2395af32e75SAxel Dörfler 2405af32e75SAxel Dörfler /* internal functions. */ 2415af32e75SAxel Dörfler extern float __copysignf (float x, float __y); 2425af32e75SAxel Dörfler 2435af32e75SAxel Dörfler 2445af32e75SAxel Dörfler /* ieee style elementary long double functions */ 2455af32e75SAxel Dörfler extern long double __ieee754_sqrtl (long double); 2465af32e75SAxel Dörfler extern long double __ieee754_acosl (long double); 2475af32e75SAxel Dörfler extern long double __ieee754_acoshl (long double); 2485af32e75SAxel Dörfler extern long double __ieee754_logl (long double); 2495af32e75SAxel Dörfler extern long double __ieee754_atanhl (long double); 2505af32e75SAxel Dörfler extern long double __ieee754_asinl (long double); 2515af32e75SAxel Dörfler extern long double __ieee754_atan2l (long double,long double); 2525af32e75SAxel Dörfler extern long double __ieee754_expl (long double); 2535af32e75SAxel Dörfler extern long double __ieee754_exp2l (long double); 2545af32e75SAxel Dörfler extern long double __ieee754_exp10l (long double); 2555af32e75SAxel Dörfler extern long double __ieee754_coshl (long double); 2565af32e75SAxel Dörfler extern long double __ieee754_fmodl (long double,long double); 2575af32e75SAxel Dörfler extern long double __ieee754_powl (long double,long double); 2585af32e75SAxel Dörfler extern long double __ieee754_lgammal_r (long double,int *); 2595af32e75SAxel Dörfler extern long double __ieee754_gammal_r (long double,int *); 2605af32e75SAxel Dörfler extern long double __ieee754_lgammal (long double); 2615af32e75SAxel Dörfler extern long double __ieee754_gammal (long double); 2625af32e75SAxel Dörfler extern long double __ieee754_log10l (long double); 2635af32e75SAxel Dörfler extern long double __ieee754_log2l (long double); 2645af32e75SAxel Dörfler extern long double __ieee754_sinhl (long double); 2655af32e75SAxel Dörfler extern long double __ieee754_hypotl (long double,long double); 2665af32e75SAxel Dörfler extern long double __ieee754_j0l (long double); 2675af32e75SAxel Dörfler extern long double __ieee754_j1l (long double); 2685af32e75SAxel Dörfler extern long double __ieee754_y0l (long double); 2695af32e75SAxel Dörfler extern long double __ieee754_y1l (long double); 2705af32e75SAxel Dörfler extern long double __ieee754_jnl (int,long double); 2715af32e75SAxel Dörfler extern long double __ieee754_ynl (int,long double); 2725af32e75SAxel Dörfler extern long double __ieee754_remainderl (long double,long double); 2735af32e75SAxel Dörfler extern int32_t __ieee754_rem_pio2l (long double,long double*); 2745af32e75SAxel Dörfler extern long double __ieee754_scalbl (long double,long double); 2755af32e75SAxel Dörfler 2765af32e75SAxel Dörfler /* long double versions of fdlibm kernel functions */ 2775af32e75SAxel Dörfler extern long double __kernel_sinl (long double,long double,int); 2785af32e75SAxel Dörfler extern long double __kernel_cosl (long double,long double); 2795af32e75SAxel Dörfler extern long double __kernel_tanl (long double,long double,int); 2805af32e75SAxel Dörfler extern void __kernel_sincosl (long double,long double, 2815af32e75SAxel Dörfler long double *,long double *, int); 2825af32e75SAxel Dörfler extern int __kernel_rem_pio2l (long double*,long double*,int,int, 2835af32e75SAxel Dörfler int,const int*); 2845af32e75SAxel Dörfler 2855af32e75SAxel Dörfler #ifndef NO_LONG_DOUBLE 2865af32e75SAxel Dörfler /* prototypes required to compile the ldbl-96 support without warnings */ 2875af32e75SAxel Dörfler extern int __finitel (long double); 2885af32e75SAxel Dörfler extern int __ilogbl (long double); 2895af32e75SAxel Dörfler extern long double __atanl (long double); 2905af32e75SAxel Dörfler extern long double __copysignl (long double, long double); 2915af32e75SAxel Dörfler extern long double __expm1l (long double); 2925af32e75SAxel Dörfler extern long double __floorl (long double); 2935af32e75SAxel Dörfler extern long double __frexpl (long double, int *); 2945af32e75SAxel Dörfler extern long double __ldexpl (long double, int); 2955af32e75SAxel Dörfler extern long double __log1pl (long double); 2965af32e75SAxel Dörfler extern long double __nanl (const char *); 2975af32e75SAxel Dörfler extern long double __rintl (long double); 2985af32e75SAxel Dörfler extern long double __scalbnl (long double, int); 2995af32e75SAxel Dörfler extern long double __sqrtl (long double x); 3005af32e75SAxel Dörfler extern long double fabsl (long double x); 3015af32e75SAxel Dörfler extern void __sincosl (long double, long double *, long double *); 3025af32e75SAxel Dörfler extern long double __logbl (long double x); 3035af32e75SAxel Dörfler extern long double __significandl (long double x); 3045af32e75SAxel Dörfler #endif 3055af32e75SAxel Dörfler 3065af32e75SAxel Dörfler /* Prototypes for functions of the IBM Accurate Mathematical Library. */ 3075af32e75SAxel Dörfler extern double __exp1 (double __x, double __xx, double __error); 3085af32e75SAxel Dörfler extern double __sin (double __x); 3095af32e75SAxel Dörfler extern double __cos (double __x); 3105af32e75SAxel Dörfler extern int __branred (double __x, double *__a, double *__aa); 3115af32e75SAxel Dörfler extern void __doasin (double __x, double __dx, double __v[]); 3125af32e75SAxel Dörfler extern void __dubsin (double __x, double __dx, double __v[]); 3135af32e75SAxel Dörfler extern void __dubcos (double __x, double __dx, double __v[]); 3145af32e75SAxel Dörfler extern double __halfulp (double __x, double __y); 3155af32e75SAxel Dörfler extern double __sin32 (double __x, double __res, double __res1); 3165af32e75SAxel Dörfler extern double __cos32 (double __x, double __res, double __res1); 3175af32e75SAxel Dörfler extern double __mpsin (double __x, double __dx); 3185af32e75SAxel Dörfler extern double __mpcos (double __x, double __dx); 3195af32e75SAxel Dörfler extern double __mpsin1 (double __x); 3205af32e75SAxel Dörfler extern double __mpcos1 (double __x); 3215af32e75SAxel Dörfler extern double __slowexp (double __x); 3225af32e75SAxel Dörfler extern double __slowpow (double __x, double __y, double __z); 3235af32e75SAxel Dörfler extern void __docos (double __x, double __dx, double __v[]); 3245af32e75SAxel Dörfler 3255af32e75SAxel Dörfler #endif /* _MATH_PRIVATE_H_ */ 326