xref: /haiku/src/system/libroot/posix/glibc/math/math_private.h (revision bc3955fea5b07e2e94a27fc05e4bb58fe6f0319b)
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
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  * ====================================================
10  */
11 
12 /*
13  * from: @(#)fdlibm.h 5.1 93/09/24
14  * $Id$
15  */
16 
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
19 
20 #include <endian.h>
21 #include <sys/types.h>
22 #include <stdint.h>
23 
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.  */
34 
35 /* A union which permits us to convert between a double and two 32 bit
36    ints.  */
37 
38 #if __FLOAT_WORD_ORDER == BIG_ENDIAN
39 
40 typedef union
41 {
42   double value;
43   struct
44   {
45     u_int32_t msw;
46     u_int32_t lsw;
47   } parts;
48 } ieee_double_shape_type;
49 
50 #endif
51 
52 #if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
53 
54 typedef union
55 {
56   double value;
57   struct
58   {
59     u_int32_t lsw;
60     u_int32_t msw;
61   } parts;
62 } ieee_double_shape_type;
63 
64 #endif
65 
66 /* Get two 32 bit ints from a double.  */
67 
68 #define EXTRACT_WORDS(ix0,ix1,d)				\
69 do {								\
70   ieee_double_shape_type ew_u;					\
71   ew_u.value = (d);						\
72   (ix0) = ew_u.parts.msw;					\
73   (ix1) = ew_u.parts.lsw;					\
74 } while (0)
75 
76 /* Get the more significant 32 bit int from a double.  */
77 
78 #define GET_HIGH_WORD(i,d)					\
79 do {								\
80   ieee_double_shape_type gh_u;					\
81   gh_u.value = (d);						\
82   (i) = gh_u.parts.msw;						\
83 } while (0)
84 
85 /* Get the less significant 32 bit int from a double.  */
86 
87 #define GET_LOW_WORD(i,d)					\
88 do {								\
89   ieee_double_shape_type gl_u;					\
90   gl_u.value = (d);						\
91   (i) = gl_u.parts.lsw;						\
92 } while (0)
93 
94 /* Set a double from two 32 bit ints.  */
95 
96 #define INSERT_WORDS(d,ix0,ix1)					\
97 do {								\
98   ieee_double_shape_type iw_u;					\
99   iw_u.parts.msw = (ix0);					\
100   iw_u.parts.lsw = (ix1);					\
101   (d) = iw_u.value;						\
102 } while (0)
103 
104 /* Set the more significant 32 bits of a double from an int.  */
105 
106 #define SET_HIGH_WORD(d,v)					\
107 do {								\
108   ieee_double_shape_type sh_u;					\
109   sh_u.value = (d);						\
110   sh_u.parts.msw = (v);						\
111   (d) = sh_u.value;						\
112 } while (0)
113 
114 /* Set the less significant 32 bits of a double from an int.  */
115 
116 #define SET_LOW_WORD(d,v)					\
117 do {								\
118   ieee_double_shape_type sl_u;					\
119   sl_u.value = (d);						\
120   sl_u.parts.lsw = (v);						\
121   (d) = sl_u.value;						\
122 } while (0)
123 
124 /* A union which permits us to convert between a float and a 32 bit
125    int.  */
126 
127 typedef union
128 {
129   float value;
130   u_int32_t word;
131 } ieee_float_shape_type;
132 
133 /* Get a 32 bit int from a float.  */
134 
135 #define GET_FLOAT_WORD(i,d)					\
136 do {								\
137   ieee_float_shape_type gf_u;					\
138   gf_u.value = (d);						\
139   (i) = gf_u.word;						\
140 } while (0)
141 
142 /* Set a float from a 32 bit int.  */
143 
144 #define SET_FLOAT_WORD(d,i)					\
145 do {								\
146   ieee_float_shape_type sf_u;					\
147   sf_u.word = (i);						\
148   (d) = sf_u.value;						\
149 } while (0)
150 
151 /* Get long double macros from a separate header.  */
152 #include <math_ldbl.h>
153 
154 /* ieee style elementary functions */
155 extern double __ieee754_sqrt (double);
156 extern double __ieee754_acos (double);
157 extern double __ieee754_acosh (double);
158 extern double __ieee754_log (double);
159 extern double __ieee754_atanh (double);
160 extern double __ieee754_asin (double);
161 extern double __ieee754_atan2 (double,double);
162 extern double __ieee754_exp (double);
163 extern double __ieee754_exp2 (double);
164 extern double __ieee754_exp10 (double);
165 extern double __ieee754_cosh (double);
166 extern double __ieee754_fmod (double,double);
167 extern double __ieee754_pow (double,double);
168 extern double __ieee754_lgamma_r (double,int *);
169 extern double __ieee754_gamma_r (double,int *);
170 extern double __ieee754_lgamma (double);
171 extern double __ieee754_gamma (double);
172 extern double __ieee754_log10 (double);
173 extern double __ieee754_log2 (double);
174 extern double __ieee754_sinh (double);
175 extern double __ieee754_hypot (double,double);
176 extern double __ieee754_j0 (double);
177 extern double __ieee754_j1 (double);
178 extern double __ieee754_y0 (double);
179 extern double __ieee754_y1 (double);
180 extern double __ieee754_jn (int,double);
181 extern double __ieee754_yn (int,double);
182 extern double __ieee754_remainder (double,double);
183 extern int32_t __ieee754_rem_pio2 (double,double*);
184 extern double __ieee754_scalb (double,double);
185 
186 /* fdlibm kernel function */
187 extern double __kernel_standard (double,double,int);
188 extern double __kernel_sin (double,double,int);
189 extern double __kernel_cos (double,double);
190 extern double __kernel_tan (double,double,int);
191 extern int    __kernel_rem_pio2 (double*,double*,int,int,int, const int32_t*);
192 
193 /* internal functions.  */
194 extern double __copysign (double x, double __y);
195 
196 
197 /* ieee style elementary float functions */
198 extern float __ieee754_sqrtf (float);
199 extern float __ieee754_acosf (float);
200 extern float __ieee754_acoshf (float);
201 extern float __ieee754_logf (float);
202 extern float __ieee754_atanhf (float);
203 extern float __ieee754_asinf (float);
204 extern float __ieee754_atan2f (float,float);
205 extern float __ieee754_expf (float);
206 extern float __ieee754_exp2f (float);
207 extern float __ieee754_exp10f (float);
208 extern float __ieee754_coshf (float);
209 extern float __ieee754_fmodf (float,float);
210 extern float __ieee754_powf (float,float);
211 extern float __ieee754_lgammaf_r (float,int *);
212 extern float __ieee754_gammaf_r (float,int *);
213 extern float __ieee754_lgammaf (float);
214 extern float __ieee754_gammaf (float);
215 extern float __ieee754_log10f (float);
216 extern float __ieee754_log2f (float);
217 extern float __ieee754_sinhf (float);
218 extern float __ieee754_hypotf (float,float);
219 extern float __ieee754_j0f (float);
220 extern float __ieee754_j1f (float);
221 extern float __ieee754_y0f (float);
222 extern float __ieee754_y1f (float);
223 extern float __ieee754_jnf (int,float);
224 extern float __ieee754_ynf (int,float);
225 extern float __ieee754_remainderf (float,float);
226 extern int32_t __ieee754_rem_pio2f (float,float*);
227 extern float __ieee754_scalbf (float,float);
228 
229 
230 /* float versions of fdlibm kernel functions */
231 extern float __kernel_sinf (float,float,int);
232 extern float __kernel_cosf (float,float);
233 extern float __kernel_tanf (float,float,int);
234 extern int   __kernel_rem_pio2f (float*,float*,int,int,int, const int32_t*);
235 
236 /* internal functions.  */
237 extern float __copysignf (float x, float __y);
238 
239 
240 /* ieee style elementary long double functions */
241 extern long double __ieee754_sqrtl (long double);
242 extern long double __ieee754_acosl (long double);
243 extern long double __ieee754_acoshl (long double);
244 extern long double __ieee754_logl (long double);
245 extern long double __ieee754_atanhl (long double);
246 extern long double __ieee754_asinl (long double);
247 extern long double __ieee754_atan2l (long double,long double);
248 extern long double __ieee754_expl (long double);
249 extern long double __ieee754_exp2l (long double);
250 extern long double __ieee754_exp10l (long double);
251 extern long double __ieee754_coshl (long double);
252 extern long double __ieee754_fmodl (long double,long double);
253 extern long double __ieee754_powl (long double,long double);
254 extern long double __ieee754_lgammal_r (long double,int *);
255 extern long double __ieee754_gammal_r (long double,int *);
256 extern long double __ieee754_lgammal (long double);
257 extern long double __ieee754_gammal (long double);
258 extern long double __ieee754_log10l (long double);
259 extern long double __ieee754_log2l (long double);
260 extern long double __ieee754_sinhl (long double);
261 extern long double __ieee754_hypotl (long double,long double);
262 extern long double __ieee754_j0l (long double);
263 extern long double __ieee754_j1l (long double);
264 extern long double __ieee754_y0l (long double);
265 extern long double __ieee754_y1l (long double);
266 extern long double __ieee754_jnl (int,long double);
267 extern long double __ieee754_ynl (int,long double);
268 extern long double __ieee754_remainderl (long double,long double);
269 extern int32_t   __ieee754_rem_pio2l (long double,long double*);
270 extern long double __ieee754_scalbl (long double,long double);
271 
272 /* long double versions of fdlibm kernel functions */
273 extern long double __kernel_sinl (long double,long double,int);
274 extern long double __kernel_cosl (long double,long double);
275 extern long double __kernel_tanl (long double,long double,int);
276 extern void __kernel_sincosl (long double,long double,
277 			      long double *,long double *, int);
278 extern int   __kernel_rem_pio2l (long double*,long double*,int,int,
279 				 int,const int*);
280 
281 #ifndef NO_LONG_DOUBLE
282 /* prototypes required to compile the ldbl-96 support without warnings */
283 extern int __finitel (long double);
284 extern int __ilogbl (long double);
285 extern int __isinfl (long double);
286 extern int __isnanl (long double);
287 extern long double __atanl (long double);
288 extern long double __copysignl (long double, long double);
289 extern long double __expm1l (long double);
290 extern long double __floorl (long double);
291 extern long double __frexpl (long double, int *);
292 extern long double __ldexpl (long double, int);
293 extern long double __log1pl (long double);
294 extern long double __nanl (const char *);
295 extern long double __rintl (long double);
296 extern long double __scalbnl (long double, int);
297 extern long double __sqrtl (long double x);
298 extern long double fabsl (long double x);
299 extern void __sincosl (long double, long double *, long double *);
300 extern long double __logbl (long double x);
301 extern long double __significandl (long double x);
302 #endif
303 
304 /* Prototypes for functions of the IBM Accurate Mathematical Library.  */
305 extern double __exp1 (double __x, double __xx, double __error);
306 extern double __sin (double __x);
307 extern double __cos (double __x);
308 extern int __branred (double __x, double *__a, double *__aa);
309 extern void __doasin (double __x, double __dx, double __v[]);
310 extern void __dubsin (double __x, double __dx, double __v[]);
311 extern void __dubcos (double __x, double __dx, double __v[]);
312 extern double __halfulp (double __x, double __y);
313 extern double __sin32 (double __x, double __res, double __res1);
314 extern double __cos32 (double __x, double __res, double __res1);
315 extern double __mpsin (double __x, double __dx);
316 extern double __mpcos (double __x, double __dx);
317 extern double __mpsin1 (double __x);
318 extern double __mpcos1 (double __x);
319 extern double __slowexp (double __x);
320 extern double __slowpow (double __x, double __y, double __z);
321 extern void __docos (double __x, double __dx, double __v[]);
322 
323 #endif /* _MATH_PRIVATE_H_ */
324