Update.
[glibc.git] / math / math_private.h
blob99be167e388995dadd18d4bd4f302580518afead
1 /*
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
8 * is preserved.
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $Id$
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include <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
35 ints. */
37 #if __FLOAT_WORD_ORDER == BIG_ENDIAN
39 typedef union
41 double value;
42 struct
44 u_int32_t msw;
45 u_int32_t lsw;
46 } parts;
47 } ieee_double_shape_type;
49 #endif
51 #if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
53 typedef union
55 double value;
56 struct
58 u_int32_t lsw;
59 u_int32_t msw;
60 } parts;
61 } ieee_double_shape_type;
63 #endif
65 /* Get two 32 bit ints from a double. */
67 #define EXTRACT_WORDS(ix0,ix1,d) \
68 do { \
69 ieee_double_shape_type ew_u; \
70 ew_u.value = (d); \
71 (ix0) = ew_u.parts.msw; \
72 (ix1) = ew_u.parts.lsw; \
73 } while (0)
75 /* Get the more significant 32 bit int from a double. */
77 #define GET_HIGH_WORD(i,d) \
78 do { \
79 ieee_double_shape_type gh_u; \
80 gh_u.value = (d); \
81 (i) = gh_u.parts.msw; \
82 } while (0)
84 /* Get the less significant 32 bit int from a double. */
86 #define GET_LOW_WORD(i,d) \
87 do { \
88 ieee_double_shape_type gl_u; \
89 gl_u.value = (d); \
90 (i) = gl_u.parts.lsw; \
91 } while (0)
93 /* Set a double from two 32 bit ints. */
95 #define INSERT_WORDS(d,ix0,ix1) \
96 do { \
97 ieee_double_shape_type iw_u; \
98 iw_u.parts.msw = (ix0); \
99 iw_u.parts.lsw = (ix1); \
100 (d) = iw_u.value; \
101 } while (0)
103 /* Set the more significant 32 bits of a double from an int. */
105 #define SET_HIGH_WORD(d,v) \
106 do { \
107 ieee_double_shape_type sh_u; \
108 sh_u.value = (d); \
109 sh_u.parts.msw = (v); \
110 (d) = sh_u.value; \
111 } while (0)
113 /* Set the less significant 32 bits of a double from an int. */
115 #define SET_LOW_WORD(d,v) \
116 do { \
117 ieee_double_shape_type sl_u; \
118 sl_u.value = (d); \
119 sl_u.parts.lsw = (v); \
120 (d) = sl_u.value; \
121 } while (0)
123 /* A union which permits us to convert between a float and a 32 bit
124 int. */
126 typedef union
128 float value;
129 u_int32_t word;
130 } ieee_float_shape_type;
132 /* Get a 32 bit int from a float. */
134 #define GET_FLOAT_WORD(i,d) \
135 do { \
136 ieee_float_shape_type gf_u; \
137 gf_u.value = (d); \
138 (i) = gf_u.word; \
139 } while (0)
141 /* Set a float from a 32 bit int. */
143 #define SET_FLOAT_WORD(d,i) \
144 do { \
145 ieee_float_shape_type sf_u; \
146 sf_u.word = (i); \
147 (d) = sf_u.value; \
148 } while (0)
150 /* Get long double macros from a separate header. */
151 #include <math_ldbl.h>
153 /* ieee style elementary functions */
154 extern double __ieee754_sqrt (double);
155 extern double __ieee754_acos (double);
156 extern double __ieee754_acosh (double);
157 extern double __ieee754_log (double);
158 extern double __ieee754_atanh (double);
159 extern double __ieee754_asin (double);
160 extern double __ieee754_atan2 (double,double);
161 extern double __ieee754_exp (double);
162 extern double __ieee754_exp2 (double);
163 extern double __ieee754_exp10 (double);
164 extern double __ieee754_cosh (double);
165 extern double __ieee754_fmod (double,double);
166 extern double __ieee754_pow (double,double);
167 extern double __ieee754_lgamma_r (double,int *);
168 extern double __ieee754_gamma_r (double,int *);
169 extern double __ieee754_lgamma (double);
170 extern double __ieee754_gamma (double);
171 extern double __ieee754_log10 (double);
172 extern double __ieee754_sinh (double);
173 extern double __ieee754_hypot (double,double);
174 extern double __ieee754_j0 (double);
175 extern double __ieee754_j1 (double);
176 extern double __ieee754_y0 (double);
177 extern double __ieee754_y1 (double);
178 extern double __ieee754_jn (int,double);
179 extern double __ieee754_yn (int,double);
180 extern double __ieee754_remainder (double,double);
181 extern int32_t __ieee754_rem_pio2 (double,double*);
182 extern double __ieee754_scalb (double,double);
184 /* fdlibm kernel function */
185 extern double __kernel_standard (double,double,int);
186 extern double __kernel_sin (double,double,int);
187 extern double __kernel_cos (double,double);
188 extern double __kernel_tan (double,double,int);
189 extern int __kernel_rem_pio2 (double*,double*,int,int,int, const int32_t*);
192 /* ieee style elementary float functions */
193 extern float __ieee754_sqrtf (float);
194 extern float __ieee754_acosf (float);
195 extern float __ieee754_acoshf (float);
196 extern float __ieee754_logf (float);
197 extern float __ieee754_atanhf (float);
198 extern float __ieee754_asinf (float);
199 extern float __ieee754_atan2f (float,float);
200 extern float __ieee754_expf (float);
201 extern float __ieee754_exp2f (float);
202 extern float __ieee754_exp10f (float);
203 extern float __ieee754_coshf (float);
204 extern float __ieee754_fmodf (float,float);
205 extern float __ieee754_powf (float,float);
206 extern float __ieee754_lgammaf_r (float,int *);
207 extern float __ieee754_gammaf_r (float,int *);
208 extern float __ieee754_lgammaf (float);
209 extern float __ieee754_gammaf (float);
210 extern float __ieee754_log10f (float);
211 extern float __ieee754_sinhf (float);
212 extern float __ieee754_hypotf (float,float);
213 extern float __ieee754_j0f (float);
214 extern float __ieee754_j1f (float);
215 extern float __ieee754_y0f (float);
216 extern float __ieee754_y1f (float);
217 extern float __ieee754_jnf (int,float);
218 extern float __ieee754_ynf (int,float);
219 extern float __ieee754_remainderf (float,float);
220 extern int32_t __ieee754_rem_pio2f (float,float*);
221 extern float __ieee754_scalbf (float,float);
223 /* float versions of fdlibm kernel functions */
224 extern float __kernel_sinf (float,float,int);
225 extern float __kernel_cosf (float,float);
226 extern float __kernel_tanf (float,float,int);
227 extern int __kernel_rem_pio2f (float*,float*,int,int,int, const int32_t*);
230 /* ieee style elementary long double functions */
231 extern long double __ieee754_sqrtl (long double);
232 extern long double __ieee754_acosl (long double);
233 extern long double __ieee754_acoshl (long double);
234 extern long double __ieee754_logl (long double);
235 extern long double __ieee754_atanhl (long double);
236 extern long double __ieee754_asinl (long double);
237 extern long double __ieee754_atan2l (long double,long double);
238 extern long double __ieee754_expl (long double);
239 extern long double __ieee754_exp2l (long double);
240 extern long double __ieee754_exp10l (long double);
241 extern long double __ieee754_coshl (long double);
242 extern long double __ieee754_fmodl (long double,long double);
243 extern long double __ieee754_powl (long double,long double);
244 extern long double __ieee754_lgammal_r (long double,int *);
245 extern long double __ieee754_gammal_r (long double,int *);
246 extern long double __ieee754_lgammal (long double);
247 extern long double __ieee754_gammal (long double);
248 extern long double __ieee754_log10l (long double);
249 extern long double __ieee754_sinhl (long double);
250 extern long double __ieee754_hypotl (long double,long double);
251 extern long double __ieee754_j0l (long double);
252 extern long double __ieee754_j1l (long double);
253 extern long double __ieee754_y0l (long double);
254 extern long double __ieee754_y1l (long double);
255 extern long double __ieee754_jnl (int,long double);
256 extern long double __ieee754_ynl (int,long double);
257 extern long double __ieee754_remainderl (long double,long double);
258 extern int __ieee754_rem_pio2l (long double,long double*);
259 extern long double __ieee754_scalbl (long double,long double);
261 /* long double versions of fdlibm kernel functions */
262 extern long double __kernel_sinl (long double,long double,int);
263 extern long double __kernel_cosl (long double,long double);
264 extern long double __kernel_tanl (long double,long double,int);
265 extern void __kernel_sincosl (long double,long double,
266 long double *,long double *, int);
267 extern int __kernel_rem_pio2l (long double*,long double*,int,int,
268 int,const int*);
270 #endif /* _MATH_PRIVATE_H_ */