* Check explicitly for isnan.
[cacao.git] / src / fdlibm / fdlibm.h
1
2 /* @(#)fdlibm.h 5.1 93/09/24 */
3 /*
4  * ====================================================
5  * Copyright (C) 1993, 2000 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Developed at SunPro, a Sun Microsystems, Inc. business.
8  * Permission to use, copy, modify, and distribute this
9  * software is freely granted, provided that this notice 
10  * is preserved.
11  * ====================================================
12  */
13
14 #ifndef __CLASSPATH_FDLIBM_H__
15 #define __CLASSPATH_FDLIBM_H__
16
17 /* AIX needs _XOPEN_SOURCE */
18 #ifdef _AIX
19 #define _XOPEN_SOURCE
20 #endif
21
22 #include <config.h>
23 #include <stdlib.h>
24
25 /* GCJ LOCAL: Include files.  */
26 #include "ieeefp.h"
27
28 #include "mprec.h"
29
30 /* CYGNUS LOCAL: Default to XOPEN_MODE.  */
31 #define _XOPEN_MODE
32
33 #ifdef __P
34 #undef __P
35 #endif
36
37 #ifdef __STDC__
38 #define __P(p)  p
39 #else
40 #define __P(p)  ()
41 #endif
42
43 #ifndef HUGE
44 #define HUGE    ((float)3.40282346638528860e+38)
45 #endif
46
47 /* 
48  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
49  * (one may replace the following line by "#include <values.h>")
50  */
51
52 #define X_TLOSS         1.41484755040568800000e+16 
53
54 /* These typedefs are true for the targets running Java. */
55
56 #define _IEEE_LIBM
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 /*
63  * ANSI/POSIX
64  */
65 extern double acos __P((double));
66 extern double asin __P((double));
67 extern double atan __P((double));
68 extern double atan2 __P((double, double));
69 extern double cos __P((double));
70 extern double sin __P((double));
71 extern double tan __P((double));
72
73 extern double cosh __P((double));
74 extern double sinh __P((double));
75 extern double tanh __P((double));
76
77 extern double exp __P((double));
78 extern double frexp __P((double, int *));
79 extern double ldexp __P((double, int));
80 extern double log __P((double));
81 extern double log10 __P((double));
82 extern double modf __P((double, double *));
83
84 extern double pow __P((double, double));
85 extern double sqrt __P((double));
86
87 extern double ceil __P((double));
88 extern double fabs __P((double));
89 extern double floor __P((double));
90 extern double fmod __P((double, double));
91
92 extern double erf __P((double));
93 extern double erfc __P((double));
94 extern double gamma __P((double));
95 extern double hypot __P((double, double));
96
97 #if !defined(isnan) && !defined(HAVE_ISNAN)
98 #define isnan(x) ((x) != (x))
99 #endif
100
101 extern int finite __P((double));
102 extern double j0 __P((double));
103 extern double j1 __P((double));
104 extern double jn __P((int, double));
105 extern double lgamma __P((double));
106 extern double y0 __P((double));
107 extern double y1 __P((double));
108 extern double yn __P((int, double));
109
110 extern double acosh __P((double));
111 extern double asinh __P((double));
112 extern double atanh __P((double));
113 extern double cbrt __P((double));
114 extern double logb __P((double));
115 extern double nextafter __P((double, double));
116 extern double remainder __P((double, double));
117
118 /* Functions that are not documented, and are not in <math.h>.  */
119
120 extern double logb __P((double));
121 #ifdef _SCALB_INT
122 extern double scalb __P((double, int));
123 #else
124 extern double scalb __P((double, double));
125 #endif
126 extern double significand __P((double));
127
128 /* ieee style elementary functions */
129 extern double __ieee754_sqrt __P((double));                     
130 extern double __ieee754_acos __P((double));                     
131 extern double __ieee754_acosh __P((double));                    
132 extern double __ieee754_log __P((double));                      
133 extern double __ieee754_atanh __P((double));                    
134 extern double __ieee754_asin __P((double));                     
135 extern double __ieee754_atan2 __P((double,double));                     
136 extern double __ieee754_exp __P((double));
137 extern double __ieee754_cosh __P((double));
138 extern double __ieee754_fmod __P((double,double));
139 extern double __ieee754_pow __P((double,double));
140 extern double __ieee754_lgamma_r __P((double,int *));
141 extern double __ieee754_gamma_r __P((double,int *));
142 extern double __ieee754_log10 __P((double));
143 extern double __ieee754_sinh __P((double));
144 extern double __ieee754_hypot __P((double,double));
145 extern double __ieee754_j0 __P((double));
146 extern double __ieee754_j1 __P((double));
147 extern double __ieee754_y0 __P((double));
148 extern double __ieee754_y1 __P((double));
149 extern double __ieee754_jn __P((int,double));
150 extern double __ieee754_yn __P((int,double));
151 extern double __ieee754_remainder __P((double,double));
152 extern int32_t __ieee754_rem_pio2 __P((double,double*));
153 #ifdef _SCALB_INT
154 extern double __ieee754_scalb __P((double,int));
155 #else
156 extern double __ieee754_scalb __P((double,double));
157 #endif
158
159 /* fdlibm kernel function */
160 extern double __kernel_standard __P((double,double,int));
161 extern double __kernel_sin __P((double,double,int));
162 extern double __kernel_cos __P((double,double));
163 extern double __kernel_tan __P((double,double,int));
164 extern int    __kernel_rem_pio2 __P((double*,double*,int,int,int,const int32_t*));
165
166 /* Undocumented float functions.  */
167 extern float logbf __P((float));
168 #ifdef _SCALB_INT
169 extern float scalbf __P((float, int));
170 #else
171 extern float scalbf __P((float, float));
172 #endif
173 extern float significandf __P((float));
174
175 /*
176  * Functions callable from C, intended to support IEEE arithmetic.
177  */
178 extern double copysign __P((double, double));
179 extern int ilogb __P((double));
180 extern double rint __P((double));
181 extern float rintf __P((float));
182 extern double scalbn __P((double, int));
183
184 /* ieee style elementary float functions */
185 extern float __ieee754_sqrtf __P((float));                      
186 extern float __ieee754_acosf __P((float));                      
187 extern float __ieee754_acoshf __P((float));                     
188 extern float __ieee754_logf __P((float));                       
189 extern float __ieee754_atanhf __P((float));                     
190 extern float __ieee754_asinf __P((float));                      
191 extern float __ieee754_atan2f __P((float,float));                       
192 extern float __ieee754_expf __P((float));
193 extern float __ieee754_coshf __P((float));
194 extern float __ieee754_fmodf __P((float,float));
195 extern float __ieee754_powf __P((float,float));
196 extern float __ieee754_lgammaf_r __P((float,int *));
197 extern float __ieee754_gammaf_r __P((float,int *));
198 extern float __ieee754_log10f __P((float));
199 extern float __ieee754_sinhf __P((float));
200 extern float __ieee754_hypotf __P((float,float));
201 extern float __ieee754_j0f __P((float));
202 extern float __ieee754_j1f __P((float));
203 extern float __ieee754_y0f __P((float));
204 extern float __ieee754_y1f __P((float));
205 extern float __ieee754_jnf __P((int,float));
206 extern float __ieee754_ynf __P((int,float));
207 extern float __ieee754_remainderf __P((float,float));
208 extern int32_t __ieee754_rem_pio2f __P((float,float*));
209 #ifdef _SCALB_INT
210 extern float __ieee754_scalbf __P((float,int));
211 #else
212 extern float __ieee754_scalbf __P((float,float));
213 #endif
214
215 /* float versions of fdlibm kernel functions */
216 extern float __kernel_sinf __P((float,float,int));
217 extern float __kernel_cosf __P((float,float));
218 extern float __kernel_tanf __P((float,float,int));
219 extern int   __kernel_rem_pio2f __P((float*,float*,int,int,int,const int32_t*));
220
221 /* The original code used statements like
222         n0 = ((*(int*)&one)>>29)^1;             * index of high word *
223         ix0 = *(n0+(int*)&x);                   * high word of x *
224         ix1 = *((1-n0)+(int*)&x);               * low word of x *
225    to dig two 32 bit words out of the 64 bit IEEE floating point
226    value.  That is non-ANSI, and, moreover, the gcc instruction
227    scheduler gets it wrong.  We instead use the following macros.
228    Unlike the original code, we determine the endianness at compile
229    time, not at run time; I don't see much benefit to selecting
230    endianness at run time.  */
231
232 #ifndef __IEEE_BIG_ENDIAN
233 #ifndef __IEEE_LITTLE_ENDIAN
234  #error Must define endianness
235 #endif
236 #endif
237
238 /* A union which permits us to convert between a double and two 32 bit
239    ints.  */
240
241 #ifdef __IEEE_BIG_ENDIAN
242
243 typedef union 
244 {
245   double value;
246   struct 
247   {
248     uint32_t msw;
249     uint32_t lsw;
250   } parts;
251 } ieee_double_shape_type;
252
253 #endif
254
255 #ifdef __IEEE_LITTLE_ENDIAN
256
257 typedef union 
258 {
259   double value;
260   struct 
261   {
262     uint32_t lsw;
263     uint32_t msw;
264   } parts;
265 } ieee_double_shape_type;
266
267 #endif
268
269 /* Get two 32 bit ints from a double.  */
270
271 #define EXTRACT_WORDS(ix0,ix1,d)                                \
272 do {                                                            \
273   ieee_double_shape_type ew_u;                                  \
274   ew_u.value = (d);                                             \
275   (ix0) = ew_u.parts.msw;                                       \
276   (ix1) = ew_u.parts.lsw;                                       \
277 } while (0)
278
279 /* Get the more significant 32 bit int from a double.  */
280
281 #define GET_HIGH_WORD(i,d)                                      \
282 do {                                                            \
283   ieee_double_shape_type gh_u;                                  \
284   gh_u.value = (d);                                             \
285   (i) = gh_u.parts.msw;                                         \
286 } while (0)
287
288 /* Get the less significant 32 bit int from a double.  */
289
290 #define GET_LOW_WORD(i,d)                                       \
291 do {                                                            \
292   ieee_double_shape_type gl_u;                                  \
293   gl_u.value = (d);                                             \
294   (i) = gl_u.parts.lsw;                                         \
295 } while (0)
296
297 /* Set a double from two 32 bit ints.  */
298
299 #define INSERT_WORDS(d,ix0,ix1)                                 \
300 do {                                                            \
301   ieee_double_shape_type iw_u;                                  \
302   iw_u.parts.msw = (ix0);                                       \
303   iw_u.parts.lsw = (ix1);                                       \
304   (d) = iw_u.value;                                             \
305 } while (0)
306
307 /* Set the more significant 32 bits of a double from an int.  */
308
309 #define SET_HIGH_WORD(d,v)                                      \
310 do {                                                            \
311   ieee_double_shape_type sh_u;                                  \
312   sh_u.value = (d);                                             \
313   sh_u.parts.msw = (v);                                         \
314   (d) = sh_u.value;                                             \
315 } while (0)
316
317 /* Set the less significant 32 bits of a double from an int.  */
318
319 #define SET_LOW_WORD(d,v)                                       \
320 do {                                                            \
321   ieee_double_shape_type sl_u;                                  \
322   sl_u.value = (d);                                             \
323   sl_u.parts.lsw = (v);                                         \
324   (d) = sl_u.value;                                             \
325 } while (0)
326
327 /* A union which permits us to convert between a float and a 32 bit
328    int.  */
329
330 typedef union
331 {
332   float value;
333   uint32_t word;
334 } ieee_float_shape_type;
335
336 /* Get a 32 bit int from a float.  */
337
338 #define GET_FLOAT_WORD(i,d)                                     \
339 do {                                                            \
340   ieee_float_shape_type gf_u;                                   \
341   gf_u.value = (d);                                             \
342   (i) = gf_u.word;                                              \
343 } while (0)
344
345 /* Set a float from a 32 bit int.  */
346
347 #define SET_FLOAT_WORD(d,i)                                     \
348 do {                                                            \
349   ieee_float_shape_type sf_u;                                   \
350   sf_u.word = (i);                                              \
351   (d) = sf_u.value;                                             \
352 } while (0)
353
354 #ifdef __cplusplus
355 }
356 #endif
357
358 #endif /* __CLASSPATH_FDLIBM_H__ */