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