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