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 <sys/types.h>
21 #include <machine/endian.h>
24 * The original fdlibm code used statements like:
25 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
26 * ix0 = *(n0+(int*)&x); * high word of x *
27 * ix1 = *((1-n0)+(int*)&x); * low word of x *
28 * to dig two 32 bit words out of the 64 bit IEEE floating point
29 * value. That is non-ANSI, and, moreover, the gcc instruction
30 * scheduler gets it wrong. We instead use the following macros.
31 * Unlike the original code, we determine the endianness at compile
32 * time, not at run time; I don't see much benefit to selecting
33 * endianness at run time.
37 * A union which permits us to convert between a double and two 32 bit
41 #if BYTE_ORDER == BIG_ENDIAN
51 } ieee_double_shape_type;
55 #if BYTE_ORDER == LITTLE_ENDIAN
65 } ieee_double_shape_type;
69 /* Get two 32 bit ints from a double. */
71 #define EXTRACT_WORDS(ix0,ix1,d) \
73 ieee_double_shape_type ew_u; \
75 (ix0) = ew_u.parts.msw; \
76 (ix1) = ew_u.parts.lsw; \
79 /* Get the more significant 32 bit int from a double. */
81 #define GET_HIGH_WORD(i,d) \
83 ieee_double_shape_type gh_u; \
85 (i) = gh_u.parts.msw; \
88 /* Get the less significant 32 bit int from a double. */
90 #define GET_LOW_WORD(i,d) \
92 ieee_double_shape_type gl_u; \
94 (i) = gl_u.parts.lsw; \
97 /* Set a double from two 32 bit ints. */
99 #define INSERT_WORDS(d,ix0,ix1) \
101 ieee_double_shape_type iw_u; \
102 iw_u.parts.msw = (ix0); \
103 iw_u.parts.lsw = (ix1); \
107 /* Set the more significant 32 bits of a double from an int. */
109 #define SET_HIGH_WORD(d,v) \
111 ieee_double_shape_type sh_u; \
113 sh_u.parts.msw = (v); \
117 /* Set the less significant 32 bits of a double from an int. */
119 #define SET_LOW_WORD(d,v) \
121 ieee_double_shape_type sl_u; \
123 sl_u.parts.lsw = (v); \
128 * A union which permits us to convert between a float and a 32 bit
135 /* FIXME: Assumes 32 bit int. */
137 } ieee_float_shape_type;
139 /* Get a 32 bit int from a float. */
141 #define GET_FLOAT_WORD(i,d) \
143 ieee_float_shape_type gf_u; \
148 /* Set a float from a 32 bit int. */
150 #define SET_FLOAT_WORD(d,i) \
152 ieee_float_shape_type sf_u; \
158 * ieee style elementary functions
160 * We rename functions here to improve other sources' diffability
163 #define __ieee754_sqrt sqrt
164 #define __ieee754_acos acos
165 #define __ieee754_acosh acosh
166 #define __ieee754_log log
167 #define __ieee754_atanh atanh
168 #define __ieee754_asin asin
169 #define __ieee754_atan2 atan2
170 #define __ieee754_exp exp
171 #define __ieee754_cosh cosh
172 #define __ieee754_fmod fmod
173 #define __ieee754_pow pow
174 #define __ieee754_lgamma lgamma
175 #define __ieee754_gamma gamma
176 #define __ieee754_lgamma_r lgamma_r
177 #define __ieee754_gamma_r gamma_r
178 #define __ieee754_log10 log10
179 #define __ieee754_sinh sinh
180 #define __ieee754_hypot hypot
181 #define __ieee754_j0 j0
182 #define __ieee754_j1 j1
183 #define __ieee754_y0 y0
184 #define __ieee754_y1 y1
185 #define __ieee754_jn jn
186 #define __ieee754_yn yn
187 #define __ieee754_remainder remainder
188 #define __ieee754_scalb scalb
189 #define __ieee754_sqrtf sqrtf
190 #define __ieee754_acosf acosf
191 #define __ieee754_acoshf acoshf
192 #define __ieee754_logf logf
193 #define __ieee754_atanhf atanhf
194 #define __ieee754_asinf asinf
195 #define __ieee754_atan2f atan2f
196 #define __ieee754_expf expf
197 #define __ieee754_coshf coshf
198 #define __ieee754_fmodf fmodf
199 #define __ieee754_powf powf
200 #define __ieee754_lgammaf lgammaf
201 #define __ieee754_gammaf gammaf
202 #define __ieee754_lgammaf_r lgammaf_r
203 #define __ieee754_gammaf_r gammaf_r
204 #define __ieee754_log10f log10f
205 #define __ieee754_sinhf sinhf
206 #define __ieee754_hypotf hypotf
207 #define __ieee754_j0f j0f
208 #define __ieee754_j1f j1f
209 #define __ieee754_y0f y0f
210 #define __ieee754_y1f y1f
211 #define __ieee754_jnf jnf
212 #define __ieee754_ynf ynf
213 #define __ieee754_remainderf remainderf
214 #define __ieee754_scalbf scalbf
216 /* fdlibm kernel function */
217 int __ieee754_rem_pio2(double,double*);
218 double __kernel_sin(double,double,int);
219 double __kernel_cos(double,double);
220 double __kernel_tan(double,double,int);
221 int __kernel_rem_pio2(double*,double*,int,int,int,const int*);
223 /* float versions of fdlibm kernel functions */
224 int __ieee754_rem_pio2f(float,float*);
225 float __kernel_sinf(float,float,int);
226 float __kernel_cosf(float,float);
227 float __kernel_tanf(float,float,int);
228 int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
230 #endif /* !_MATH_PRIVATE_H_ */