1 |
148 |
jeremybenn |
/*
|
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: math_private.h 148 2010-06-30 19:21:22Z jeremybennett $
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
#ifndef _MATH_PRIVATE_H_
|
18 |
|
|
#define _MATH_PRIVATE_H_
|
19 |
|
|
|
20 |
|
|
#include <endian.h>
|
21 |
|
|
#include <sys/types.h>
|
22 |
|
|
#include <machine/weakalias.h>
|
23 |
|
|
#include <machine/huge_val.h>
|
24 |
|
|
|
25 |
|
|
#define INFINITY HUGE_VALF
|
26 |
|
|
|
27 |
|
|
#define __nan nan
|
28 |
|
|
#define __isnan isnan
|
29 |
|
|
#define __isinf isinf
|
30 |
|
|
#define __copysignf copysignf
|
31 |
|
|
#define __copysign copysign
|
32 |
|
|
#define __isnanf isnanf
|
33 |
|
|
#define __isinff isinff
|
34 |
|
|
#define __nanf nanf
|
35 |
|
|
#define feraiseexcept(x) /* nothing */
|
36 |
|
|
#define __sincos sincos
|
37 |
|
|
#define __sincosf sincosf
|
38 |
|
|
|
39 |
|
|
int __signbitd (double x);
|
40 |
|
|
int __signbitf (float x);
|
41 |
|
|
|
42 |
|
|
/* The original fdlibm code used statements like:
|
43 |
|
|
n0 = ((*(int*)&one)>>29)^1; * index of high word *
|
44 |
|
|
ix0 = *(n0+(int*)&x); * high word of x *
|
45 |
|
|
ix1 = *((1-n0)+(int*)&x); * low word of x *
|
46 |
|
|
to dig two 32 bit words out of the 64 bit IEEE floating point
|
47 |
|
|
value. That is non-ANSI, and, moreover, the gcc instruction
|
48 |
|
|
scheduler gets it wrong. We instead use the following macros.
|
49 |
|
|
Unlike the original code, we determine the endianness at compile
|
50 |
|
|
time, not at run time; I don't see much benefit to selecting
|
51 |
|
|
endianness at run time. */
|
52 |
|
|
|
53 |
|
|
/* A union which permits us to convert between a double and two 32 bit
|
54 |
|
|
ints. */
|
55 |
|
|
|
56 |
|
|
#if __FLOAT_WORD_ORDER == BIG_ENDIAN
|
57 |
|
|
|
58 |
|
|
typedef union
|
59 |
|
|
{
|
60 |
|
|
double value;
|
61 |
|
|
struct
|
62 |
|
|
{
|
63 |
|
|
u_int32_t msw;
|
64 |
|
|
u_int32_t lsw;
|
65 |
|
|
} parts;
|
66 |
|
|
} ieee_double_shape_type;
|
67 |
|
|
|
68 |
|
|
#endif
|
69 |
|
|
|
70 |
|
|
#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
|
71 |
|
|
|
72 |
|
|
typedef union
|
73 |
|
|
{
|
74 |
|
|
double value;
|
75 |
|
|
struct
|
76 |
|
|
{
|
77 |
|
|
u_int32_t lsw;
|
78 |
|
|
u_int32_t msw;
|
79 |
|
|
} parts;
|
80 |
|
|
} ieee_double_shape_type;
|
81 |
|
|
|
82 |
|
|
#endif
|
83 |
|
|
|
84 |
|
|
/* Get two 32 bit ints from a double. */
|
85 |
|
|
|
86 |
|
|
#define EXTRACT_WORDS(ix0,ix1,d) \
|
87 |
|
|
do { \
|
88 |
|
|
ieee_double_shape_type ew_u; \
|
89 |
|
|
ew_u.value = (d); \
|
90 |
|
|
(ix0) = ew_u.parts.msw; \
|
91 |
|
|
(ix1) = ew_u.parts.lsw; \
|
92 |
|
|
} while (0)
|
93 |
|
|
|
94 |
|
|
/* Get the more significant 32 bit int from a double. */
|
95 |
|
|
|
96 |
|
|
#define GET_HIGH_WORD(i,d) \
|
97 |
|
|
do { \
|
98 |
|
|
ieee_double_shape_type gh_u; \
|
99 |
|
|
gh_u.value = (d); \
|
100 |
|
|
(i) = gh_u.parts.msw; \
|
101 |
|
|
} while (0)
|
102 |
|
|
|
103 |
|
|
/* Get the less significant 32 bit int from a double. */
|
104 |
|
|
|
105 |
|
|
#define GET_LOW_WORD(i,d) \
|
106 |
|
|
do { \
|
107 |
|
|
ieee_double_shape_type gl_u; \
|
108 |
|
|
gl_u.value = (d); \
|
109 |
|
|
(i) = gl_u.parts.lsw; \
|
110 |
|
|
} while (0)
|
111 |
|
|
|
112 |
|
|
/* Set a double from two 32 bit ints. */
|
113 |
|
|
|
114 |
|
|
#define INSERT_WORDS(d,ix0,ix1) \
|
115 |
|
|
do { \
|
116 |
|
|
ieee_double_shape_type iw_u; \
|
117 |
|
|
iw_u.parts.msw = (ix0); \
|
118 |
|
|
iw_u.parts.lsw = (ix1); \
|
119 |
|
|
(d) = iw_u.value; \
|
120 |
|
|
} while (0)
|
121 |
|
|
|
122 |
|
|
/* Set the more significant 32 bits of a double from an int. */
|
123 |
|
|
|
124 |
|
|
#define SET_HIGH_WORD(d,v) \
|
125 |
|
|
do { \
|
126 |
|
|
ieee_double_shape_type sh_u; \
|
127 |
|
|
sh_u.value = (d); \
|
128 |
|
|
sh_u.parts.msw = (v); \
|
129 |
|
|
(d) = sh_u.value; \
|
130 |
|
|
} while (0)
|
131 |
|
|
|
132 |
|
|
/* Set the less significant 32 bits of a double from an int. */
|
133 |
|
|
|
134 |
|
|
#define SET_LOW_WORD(d,v) \
|
135 |
|
|
do { \
|
136 |
|
|
ieee_double_shape_type sl_u; \
|
137 |
|
|
sl_u.value = (d); \
|
138 |
|
|
sl_u.parts.lsw = (v); \
|
139 |
|
|
(d) = sl_u.value; \
|
140 |
|
|
} while (0)
|
141 |
|
|
|
142 |
|
|
/* A union which permits us to convert between a float and a 32 bit
|
143 |
|
|
int. */
|
144 |
|
|
|
145 |
|
|
typedef union
|
146 |
|
|
{
|
147 |
|
|
float value;
|
148 |
|
|
u_int32_t word;
|
149 |
|
|
} ieee_float_shape_type;
|
150 |
|
|
|
151 |
|
|
/* Get a 32 bit int from a float. */
|
152 |
|
|
|
153 |
|
|
#define GET_FLOAT_WORD(i,d) \
|
154 |
|
|
do { \
|
155 |
|
|
ieee_float_shape_type gf_u; \
|
156 |
|
|
gf_u.value = (d); \
|
157 |
|
|
(i) = gf_u.word; \
|
158 |
|
|
} while (0)
|
159 |
|
|
|
160 |
|
|
/* Set a float from a 32 bit int. */
|
161 |
|
|
|
162 |
|
|
#define SET_FLOAT_WORD(d,i) \
|
163 |
|
|
do { \
|
164 |
|
|
ieee_float_shape_type sf_u; \
|
165 |
|
|
sf_u.word = (i); \
|
166 |
|
|
(d) = sf_u.value; \
|
167 |
|
|
} while (0)
|
168 |
|
|
|
169 |
|
|
#if 0
|
170 |
|
|
/* ieee style elementary functions */
|
171 |
|
|
extern double __ieee754_sqrt (double);
|
172 |
|
|
extern double __ieee754_acos (double);
|
173 |
|
|
extern double __ieee754_acosh (double);
|
174 |
|
|
extern double __ieee754_log (double);
|
175 |
|
|
extern double __ieee754_atanh (double);
|
176 |
|
|
extern double __ieee754_asin (double);
|
177 |
|
|
extern double __ieee754_atan2 (double,double);
|
178 |
|
|
extern double __ieee754_exp (double);
|
179 |
|
|
extern double __ieee754_exp2 (double);
|
180 |
|
|
extern double __ieee754_exp10 (double);
|
181 |
|
|
extern double __ieee754_cosh (double);
|
182 |
|
|
extern double __ieee754_fmod (double,double);
|
183 |
|
|
extern double __ieee754_pow (double,double);
|
184 |
|
|
extern double __ieee754_lgamma_r (double,int *);
|
185 |
|
|
extern double __ieee754_gamma_r (double,int *);
|
186 |
|
|
extern double __ieee754_lgamma (double);
|
187 |
|
|
extern double __ieee754_gamma (double);
|
188 |
|
|
extern double __ieee754_log10 (double);
|
189 |
|
|
extern double __ieee754_log2 (double);
|
190 |
|
|
extern double __ieee754_sinh (double);
|
191 |
|
|
extern double __ieee754_hypot (double,double);
|
192 |
|
|
extern double __ieee754_j0 (double);
|
193 |
|
|
extern double __ieee754_j1 (double);
|
194 |
|
|
extern double __ieee754_y0 (double);
|
195 |
|
|
extern double __ieee754_y1 (double);
|
196 |
|
|
extern double __ieee754_jn (int,double);
|
197 |
|
|
extern double __ieee754_yn (int,double);
|
198 |
|
|
extern double __ieee754_remainder (double,double);
|
199 |
|
|
extern int32_t __ieee754_rem_pio2 (double,double*);
|
200 |
|
|
extern double __ieee754_scalb (double,double);
|
201 |
|
|
#endif
|
202 |
|
|
|
203 |
|
|
/* This is necessary because the hardware accelerated version of libm
|
204 |
|
|
does not provide the __ieee754 functions. */
|
205 |
|
|
#define __ieee754_sinh sinh
|
206 |
|
|
#define __ieee754_hypot hypot
|
207 |
|
|
#define __ieee754_hypotf hypotf
|
208 |
|
|
#define __ieee754_logf logf
|
209 |
|
|
#define __ieee754_log10 log10
|
210 |
|
|
#define __ieee754_exp exp
|
211 |
|
|
#define __ieee754_cosh cosh
|
212 |
|
|
#define __ieee754_expf expf
|
213 |
|
|
#define __ieee754_log10f log10f
|
214 |
|
|
#define __ieee754_atan2 atan2
|
215 |
|
|
#define __ieee754_sqrtf sqrtf
|
216 |
|
|
#define __ieee754_sinhf sinhf
|
217 |
|
|
#define __ieee754_log log
|
218 |
|
|
#define __ieee754_sqrt sqrt
|
219 |
|
|
#define __ieee754_coshf coshf
|
220 |
|
|
#define __ieee754_atan2f atan2f
|
221 |
|
|
|
222 |
|
|
/* fdlibm kernel function */
|
223 |
|
|
extern double __kernel_standard (double,double,int);
|
224 |
|
|
extern double __kernel_sin (double,double,int);
|
225 |
|
|
extern double __kernel_cos (double,double);
|
226 |
|
|
extern double __kernel_tan (double,double,int);
|
227 |
|
|
extern int __kernel_rem_pio2 (double*,double*,int,int,int, const int32_t*);
|
228 |
|
|
|
229 |
|
|
/* internal functions. */
|
230 |
|
|
extern double __copysign (double x, double __y);
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
/* ieee style elementary float functions */
|
234 |
|
|
extern float __ieee754_sqrtf (float);
|
235 |
|
|
extern float __ieee754_acosf (float);
|
236 |
|
|
extern float __ieee754_acoshf (float);
|
237 |
|
|
extern float __ieee754_logf (float);
|
238 |
|
|
extern float __ieee754_atanhf (float);
|
239 |
|
|
extern float __ieee754_asinf (float);
|
240 |
|
|
extern float __ieee754_atan2f (float,float);
|
241 |
|
|
extern float __ieee754_expf (float);
|
242 |
|
|
extern float __ieee754_exp2f (float);
|
243 |
|
|
extern float __ieee754_exp10f (float);
|
244 |
|
|
extern float __ieee754_coshf (float);
|
245 |
|
|
extern float __ieee754_fmodf (float,float);
|
246 |
|
|
extern float __ieee754_powf (float,float);
|
247 |
|
|
extern float __ieee754_lgammaf_r (float,int *);
|
248 |
|
|
extern float __ieee754_gammaf_r (float,int *);
|
249 |
|
|
extern float __ieee754_lgammaf (float);
|
250 |
|
|
extern float __ieee754_gammaf (float);
|
251 |
|
|
extern float __ieee754_log10f (float);
|
252 |
|
|
extern float __ieee754_log2f (float);
|
253 |
|
|
extern float __ieee754_sinhf (float);
|
254 |
|
|
extern float __ieee754_hypotf (float,float);
|
255 |
|
|
extern float __ieee754_j0f (float);
|
256 |
|
|
extern float __ieee754_j1f (float);
|
257 |
|
|
extern float __ieee754_y0f (float);
|
258 |
|
|
extern float __ieee754_y1f (float);
|
259 |
|
|
extern float __ieee754_jnf (int,float);
|
260 |
|
|
extern float __ieee754_ynf (int,float);
|
261 |
|
|
extern float __ieee754_remainderf (float,float);
|
262 |
|
|
extern int32_t __ieee754_rem_pio2f (float,float*);
|
263 |
|
|
extern float __ieee754_scalbf (float,float);
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
/* float versions of fdlibm kernel functions */
|
267 |
|
|
extern float __kernel_sinf (float,float,int);
|
268 |
|
|
extern float __kernel_cosf (float,float);
|
269 |
|
|
extern float __kernel_tanf (float,float,int);
|
270 |
|
|
extern int __kernel_rem_pio2f (float*,float*,int,int,int, const int32_t*);
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
/* ieee style elementary long double functions */
|
274 |
|
|
extern long double __ieee754_sqrtl (long double);
|
275 |
|
|
extern long double __ieee754_acosl (long double);
|
276 |
|
|
extern long double __ieee754_acoshl (long double);
|
277 |
|
|
extern long double __ieee754_logl (long double);
|
278 |
|
|
extern long double __ieee754_atanhl (long double);
|
279 |
|
|
extern long double __ieee754_asinl (long double);
|
280 |
|
|
extern long double __ieee754_atan2l (long double,long double);
|
281 |
|
|
extern long double __ieee754_expl (long double);
|
282 |
|
|
extern long double __ieee754_exp2l (long double);
|
283 |
|
|
extern long double __ieee754_exp10l (long double);
|
284 |
|
|
extern long double __ieee754_coshl (long double);
|
285 |
|
|
extern long double __ieee754_fmodl (long double,long double);
|
286 |
|
|
extern long double __ieee754_powl (long double,long double);
|
287 |
|
|
extern long double __ieee754_lgammal_r (long double,int *);
|
288 |
|
|
extern long double __ieee754_gammal_r (long double,int *);
|
289 |
|
|
extern long double __ieee754_lgammal (long double);
|
290 |
|
|
extern long double __ieee754_gammal (long double);
|
291 |
|
|
extern long double __ieee754_log10l (long double);
|
292 |
|
|
extern long double __ieee754_log2l (long double);
|
293 |
|
|
extern long double __ieee754_sinhl (long double);
|
294 |
|
|
extern long double __ieee754_hypotl (long double,long double);
|
295 |
|
|
extern long double __ieee754_j0l (long double);
|
296 |
|
|
extern long double __ieee754_j1l (long double);
|
297 |
|
|
extern long double __ieee754_y0l (long double);
|
298 |
|
|
extern long double __ieee754_y1l (long double);
|
299 |
|
|
extern long double __ieee754_jnl (int,long double);
|
300 |
|
|
extern long double __ieee754_ynl (int,long double);
|
301 |
|
|
extern long double __ieee754_remainderl (long double,long double);
|
302 |
|
|
extern int __ieee754_rem_pio2l (long double,long double*);
|
303 |
|
|
extern long double __ieee754_scalbl (long double,long double);
|
304 |
|
|
|
305 |
|
|
/* long double versions of fdlibm kernel functions */
|
306 |
|
|
extern long double __kernel_sinl (long double,long double,int);
|
307 |
|
|
extern long double __kernel_cosl (long double,long double);
|
308 |
|
|
extern long double __kernel_tanl (long double,long double,int);
|
309 |
|
|
extern void __kernel_sincosl (long double,long double,
|
310 |
|
|
long double *,long double *, int);
|
311 |
|
|
extern int __kernel_rem_pio2l (long double*,long double*,int,int,
|
312 |
|
|
int,const int*);
|
313 |
|
|
|
314 |
|
|
#ifndef NO_LONG_DOUBLE
|
315 |
|
|
/* prototypes required to compile the ldbl-96 support without warnings */
|
316 |
|
|
extern int __finitel (long double);
|
317 |
|
|
extern int __ilogbl (long double);
|
318 |
|
|
extern int __isinfl (long double);
|
319 |
|
|
extern int __isnanl (long double);
|
320 |
|
|
extern long double __atanl (long double);
|
321 |
|
|
extern long double __copysignl (long double, long double);
|
322 |
|
|
extern long double __expm1l (long double);
|
323 |
|
|
extern long double __floorl (long double);
|
324 |
|
|
extern long double __frexpl (long double, int *);
|
325 |
|
|
extern long double __ldexpl (long double, int);
|
326 |
|
|
extern long double __log1pl (long double);
|
327 |
|
|
extern long double __nanl (const char *);
|
328 |
|
|
extern long double __rintl (long double);
|
329 |
|
|
extern long double __scalbnl (long double, int);
|
330 |
|
|
extern long double __sqrtl (long double x);
|
331 |
|
|
extern long double fabsl (long double x);
|
332 |
|
|
extern void __sincosl (long double, long double *, long double *);
|
333 |
|
|
extern long double __logbl (long double x);
|
334 |
|
|
extern long double __significandl (long double x);
|
335 |
|
|
#endif
|
336 |
|
|
|
337 |
|
|
/* Prototypes for functions of the IBM Accurate Mathematical Library. */
|
338 |
|
|
extern double __exp1 (double __x, double __xx, double __error);
|
339 |
|
|
extern double __sin (double __x);
|
340 |
|
|
extern double __cos (double __x);
|
341 |
|
|
extern int __branred (double __x, double *__a, double *__aa);
|
342 |
|
|
extern void __doasin (double __x, double __dx, double __v[]);
|
343 |
|
|
extern void __dubsin (double __x, double __dx, double __v[]);
|
344 |
|
|
extern void __dubcos (double __x, double __dx, double __v[]);
|
345 |
|
|
extern double __halfulp (double __x, double __y);
|
346 |
|
|
extern double __sin32 (double __x, double __res, double __res1);
|
347 |
|
|
extern double __cos32 (double __x, double __res, double __res1);
|
348 |
|
|
extern double __mpsin (double __x, double __dx);
|
349 |
|
|
extern double __mpcos (double __x, double __dx);
|
350 |
|
|
extern double __mpsin1 (double __x);
|
351 |
|
|
extern double __mpcos1 (double __x);
|
352 |
|
|
extern double __slowexp (double __x);
|
353 |
|
|
extern double __slowpow (double __x, double __y, double __z);
|
354 |
|
|
extern void __docos (double __x, double __dx, double __v[]);
|
355 |
|
|
|
356 |
|
|
#endif /* _MATH_PRIVATE_H_ */
|