* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / src / fdlibm / fdlibm.h
1
2 /* @(#)fdlibm.h 1.5 04/04/22 */
3 /*
4  * ====================================================
5  * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice 
9  * is preserved.
10  * ====================================================
11  */
12
13 #ifndef __CLASSPATH_FDLIBM_H__
14 #define __CLASSPATH_FDLIBM_H__
15
16 /* AIX needs _XOPEN_SOURCE */
17 #ifdef _AIX
18 #define _XOPEN_SOURCE
19 #endif
20
21 #include <config.h>
22 #include <stdlib.h>
23
24 /* GCJ LOCAL: Include files.  */
25 #include "ieeefp.h"
26 /* CLASSPATH LOCAL: */
27 /* #include "namespace.h" */
28
29 #include "mprec.h"
30
31 /* CYGNUS LOCAL: Default to XOPEN_MODE.  */
32 #define _XOPEN_MODE
33
34 #ifdef __P
35 #undef __P
36 #endif
37
38 /* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly
39    but these catch some common cases. */
40
41 #if 0
42 #if defined(i386) || defined(i486) || \
43         defined(intel) || defined(x86) || defined(i86pc) || \
44         defined(__alpha) || defined(__osf__)
45 #define __LITTLE_ENDIAN
46 #endif
47
48 #ifdef __LITTLE_ENDIAN
49 #define __HI(x) *(1+(int*)&x)
50 #define __LO(x) *(int*)&x
51 #define __HIp(x) *(1+(int*)x)
52 #define __LOp(x) *(int*)x
53 #else
54 #define __HI(x) *(int*)&x
55 #define __LO(x) *(1+(int*)&x)
56 #define __HIp(x) *(int*)x
57 #define __LOp(x) *(1+(int*)x)
58 #endif
59 #endif
60
61 #ifdef __STDC__
62 #define __P(p)  p
63 #else
64 #define __P(p)  ()
65 #endif
66
67 /*
68  * ANSI/POSIX
69  */
70
71 extern int signgam;
72
73 #ifndef MAXFLOAT
74 #define MAXFLOAT        ((float)3.40282346638528860e+38)
75 #endif
76
77 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
78
79 #define _LIB_VERSION_TYPE enum fdversion
80 #define _LIB_VERSION _fdlib_version  
81
82 /* if global variable _LIB_VERSION is not desirable, one may 
83  * change the following to be a constant by: 
84  *      #define _LIB_VERSION_TYPE const enum version
85  * In that case, after one initializes the value _LIB_VERSION (see
86  * s_lib_version.c) during compile time, it cannot be modified
87  * in the middle of a program
88  */ 
89 extern  _LIB_VERSION_TYPE  _LIB_VERSION;
90
91 #define _IEEE_  fdlibm_ieee
92 #define _SVID_  fdlibm_svid
93 #define _XOPEN_ fdlibm_xopen
94 #define _POSIX_ fdlibm_posix
95
96 /* struct exception { */
97 /*      int type; */
98 /*      char *name; */
99 /*      double arg1; */
100 /*      double arg2; */
101 /*      double retval; */
102 /* }; */
103
104 #define HUGE            MAXFLOAT
105
106 /* 
107  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
108  * (one may replace the following line by "#include <values.h>")
109  */
110
111 #define X_TLOSS         1.41484755040568800000e+16 
112
113 #define DOMAIN          1
114 #define SING            2
115 #define OVERFLOW        3
116 #define UNDERFLOW       4
117 #define TLOSS           5
118 #define PLOSS           6
119
120 /* These typedefs are true for the targets running Java. */
121
122 #define _IEEE_LIBM
123
124 #ifdef __cplusplus
125 extern "C" {
126 #endif
127
128 /*
129  * ANSI/POSIX
130  */
131 extern double acos __P((double));
132 extern double asin __P((double));
133 extern double atan __P((double));
134 extern double atan2 __P((double, double));
135 extern double cos __P((double));
136 extern double sin __P((double));
137 extern double tan __P((double));
138
139 extern double cosh __P((double));
140 extern double sinh __P((double));
141 extern double tanh __P((double));
142
143 extern double exp __P((double));
144 extern double frexp __P((double, int *));
145 extern double ldexp __P((double, int));
146 extern double log __P((double));
147 extern double log10 __P((double));
148 extern double modf __P((double, double *));
149
150 extern double pow __P((double, double));
151 extern double sqrt __P((double));
152
153 extern double ceil __P((double));
154 extern double fabs __P((double));
155 extern double floor __P((double));
156 extern double fmod __P((double, double));
157
158 extern double erf __P((double));
159 extern double erfc __P((double));
160 extern double gamma __P((double));
161 extern double hypot __P((double, double));
162
163 #if !defined(isnan)
164 #define isnan(x) ((x) != (x))
165 #endif
166
167 extern int finite __P((double));
168 extern double j0 __P((double));
169 extern double j1 __P((double));
170 extern double jn __P((int, double));
171 extern double lgamma __P((double));
172 extern double y0 __P((double));
173 extern double y1 __P((double));
174 extern double yn __P((int, double));
175
176 extern double acosh __P((double));
177 extern double asinh __P((double));
178 extern double atanh __P((double));
179 extern double cbrt __P((double));
180 extern double logb __P((double));
181 extern double nextafter __P((double, double));
182 extern double remainder __P((double, double));
183 #ifdef _SCALB_INT
184 extern double scalb __P((double, int));
185 #else
186 extern double scalb __P((double, double));
187 #endif
188
189 /* extern int matherr __P((struct exception *)); */
190
191 /*
192  * IEEE Test Vector
193  */
194 extern double significand __P((double));
195
196 /*
197  * Functions callable from C, intended to support IEEE arithmetic.
198  */
199 extern double copysign __P((double, double));
200 extern int ilogb __P((double));
201 extern double rint __P((double));
202 extern double scalbn __P((double, int));
203
204 /*
205  * BSD math library entry points
206  */
207 extern double expm1 __P((double));
208 extern double log1p __P((double));
209
210 /*
211  * Reentrant version of gamma & lgamma; passes signgam back by reference
212  * as the second argument; user must allocate space for signgam.
213  */
214 #ifdef _REENTRANT
215 extern double gamma_r __P((double, int *));
216 extern double lgamma_r __P((double, int *));
217 #endif  /* _REENTRANT */
218
219 /* ieee style elementary functions */
220 extern double __ieee754_sqrt __P((double));                     
221 extern double __ieee754_acos __P((double));                     
222 extern double __ieee754_acosh __P((double));                    
223 extern double __ieee754_log __P((double));                      
224 extern double __ieee754_atanh __P((double));                    
225 extern double __ieee754_asin __P((double));                     
226 extern double __ieee754_atan2 __P((double,double));                     
227 extern double __ieee754_exp __P((double));
228 extern double __ieee754_cosh __P((double));
229 extern double __ieee754_fmod __P((double,double));
230 extern double __ieee754_pow __P((double,double));
231 extern double __ieee754_lgamma_r __P((double,int *));
232 extern double __ieee754_gamma_r __P((double,int *));
233 extern double __ieee754_lgamma __P((double));
234 extern double __ieee754_gamma __P((double));
235 extern double __ieee754_log10 __P((double));
236 extern double __ieee754_sinh __P((double));
237 extern double __ieee754_hypot __P((double,double));
238 extern double __ieee754_j0 __P((double));
239 extern double __ieee754_j1 __P((double));
240 extern double __ieee754_y0 __P((double));
241 extern double __ieee754_y1 __P((double));
242 extern double __ieee754_jn __P((int,double));
243 extern double __ieee754_yn __P((int,double));
244 extern double __ieee754_remainder __P((double,double));
245 extern int32_t    __ieee754_rem_pio2 __P((double,double*));
246 #ifdef _SCALB_INT
247 extern double __ieee754_scalb __P((double,int));
248 #else
249 extern double __ieee754_scalb __P((double,double));
250 #endif
251
252 /* fdlibm kernel function */
253 extern double __kernel_standard __P((double,double,int));       
254 extern double __kernel_sin __P((double,double,int));
255 extern double __kernel_cos __P((double,double));
256 extern double __kernel_tan __P((double,double,int));
257 extern int    __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
258
259 /* Classpath extensions */
260
261 /* The original code used statements like  
262    n0 = ((*(int*)&one)>>29)^1;             * index of high word *  
263    ix0 = *(n0+(int*)&x);                   * high word of x *  
264    ix1 = *((1-n0)+(int*)&x);               * low word of x *  
265    to dig two 32 bit words out of the 64 bit IEEE floating point  
266    value.  That is non-ANSI, and, moreover, the gcc instruction  
267    scheduler gets it wrong.  We instead use the following macros.  
268    Unlike the original code, we determine the endianness at compile  
269    time, not at run time; I don't see much benefit to selecting  
270    endianness at run time.  */  
271    
272 #ifndef __IEEE_BIG_ENDIAN  
273 #ifndef __IEEE_LITTLE_ENDIAN  
274 #error Must define endianness  
275 #endif  
276 #endif  
277    
278 /* A union which permits us to convert between a double and two 32 bit  
279    ints.  */  
280    
281 #ifdef __IEEE_BIG_ENDIAN  
282    
283   typedef union  
284   {  
285     double value;  
286     struct  
287     {  
288       uint32_t msw;  
289       uint32_t lsw;  
290     } parts;  
291   } ieee_double_shape_type;  
292    
293 #endif  
294    
295 #ifdef __IEEE_LITTLE_ENDIAN  
296    
297   typedef union  
298   {  
299     double value;  
300     struct  
301     {  
302       uint32_t lsw;  
303       uint32_t msw;  
304     } parts;  
305   } ieee_double_shape_type;  
306    
307 #endif  
308    
309   /* Get two 32 bit ints from a double.  */  
310    
311 #define EXTRACT_WORDS(ix0,ix1,d)                                  \
312   do {                                                            \
313     ieee_double_shape_type ew_u;                                  \
314     ew_u.value = (d);                                             \
315     (ix0) = ew_u.parts.msw;                                       \
316     (ix1) = ew_u.parts.lsw;                                       \
317   } while (0)  
318         
319 /* Get the more significant 32 bit int from a double.  */  
320         
321 #define GET_HIGH_WORD(i,d)                                      \
322   do {                                                            \
323     ieee_double_shape_type gh_u;                                  \
324     gh_u.value = (d);                                             \
325     (i) = gh_u.parts.msw;                                         \
326   } while (0)  
327         
328 /* Get the less significant 32 bit int from a double.  */  
329         
330 #define GET_LOW_WORD(i,d)                                       \
331   do {                                                            \
332     ieee_double_shape_type gl_u;                                  \
333     gl_u.value = (d);                                             \
334     (i) = gl_u.parts.lsw;                                         \
335   } while (0)  
336         
337 /* Set a double from two 32 bit ints.  */  
338         
339 #define INSERT_WORDS(d,ix0,ix1)                                 \
340   do {                                                            \
341     ieee_double_shape_type iw_u;                                  \
342     iw_u.parts.msw = (ix0);                                       \
343     iw_u.parts.lsw = (ix1);                                       \
344     (d) = iw_u.value;                                             \
345   } while (0)  
346         
347 /* Set the more significant 32 bits of a double from an int.  */  
348         
349 #define SET_HIGH_WORD(d,v)                                      \
350   do {                                                            \
351     ieee_double_shape_type sh_u;                                  \
352     sh_u.value = (d);                                             \
353     sh_u.parts.msw = (v);                                         \
354     (d) = sh_u.value;                                             \
355   } while (0)  
356         
357 /* Set the less significant 32 bits of a double from an int.  */  
358         
359 #define SET_LOW_WORD(d,v)                                       \
360   do {                                                            \
361     ieee_double_shape_type sl_u;                                  \
362     sl_u.value = (d);                                             \
363     sl_u.parts.lsw = (v);                                         \
364     (d) = sl_u.value;                                             \
365   } while (0)  
366
367 /* A union which permits us to convert between a float and a 32 bit
368    int.  */
369
370 typedef union
371 {
372   float value;
373   uint32_t word;
374 } ieee_float_shape_type;
375
376 /* Get a 32 bit int from a float.  */
377
378 #define GET_FLOAT_WORD(i,d)                                     \
379 do {                                                            \
380   ieee_float_shape_type gf_u;                                   \
381   gf_u.value = (d);                                             \
382   (i) = gf_u.word;                                              \
383 } while (0)
384
385 /* Set a float from a 32 bit int.  */
386
387 #define SET_FLOAT_WORD(d,i)                                     \
388 do {                                                            \
389   ieee_float_shape_type sf_u;                                   \
390   sf_u.word = (i);                                              \
391   (d) = sf_u.value;                                             \
392 } while (0)
393
394 #ifdef __cplusplus
395 }
396 #endif
397
398 #endif /* __CLASSPATH_FDLIBM_H__ */
399