2 /* @(#)fdlibm.h 1.5 04/04/22 */
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
10 * ====================================================
13 #ifndef __CLASSPATH_FDLIBM_H__
14 #define __CLASSPATH_FDLIBM_H__
16 /* AIX needs _XOPEN_SOURCE */
24 /* GCJ LOCAL: Include files. */
26 /* CLASSPATH LOCAL: */
27 /* #include "namespace.h" */
31 /* CYGNUS LOCAL: Default to XOPEN_MODE. */
38 /* Sometimes it's necessary to define __LITTLE_ENDIAN explicitly
39 but these catch some common cases. */
42 #if defined(i386) || defined(i486) || \
43 defined(intel) || defined(x86) || defined(i86pc) || \
44 defined(__alpha) || defined(__osf__)
45 #define __LITTLE_ENDIAN
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
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)
73 #define MAXFLOAT ((float)3.40282346638528860e+38)
75 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
77 #define _LIB_VERSION_TYPE enum fdversion
78 #define _LIB_VERSION _fdlib_version
80 /* if global variable _LIB_VERSION is not desirable, one may
81 * change the following to be a constant by:
82 * #define _LIB_VERSION_TYPE const enum version
83 * In that case, after one initializes the value _LIB_VERSION (see
84 * s_lib_version.c) during compile time, it cannot be modified
85 * in the middle of a program
87 extern _LIB_VERSION_TYPE _LIB_VERSION;
89 #define _IEEE_ fdlibm_ieee
90 #define _SVID_ fdlibm_svid
91 #define _XOPEN_ fdlibm_xopen
92 #define _POSIX_ fdlibm_posix
102 #define HUGE MAXFLOAT
105 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
106 * (one may replace the following line by "#include <values.h>")
109 #define X_TLOSS 1.41484755040568800000e+16
118 /* These typedefs are true for the targets running Java. */
129 extern double acos __P((double));
130 extern double asin __P((double));
131 extern double atan __P((double));
132 extern double atan2 __P((double, double));
133 extern double cos __P((double));
134 extern double sin __P((double));
135 extern double tan __P((double));
137 extern double cosh __P((double));
138 extern double sinh __P((double));
139 extern double tanh __P((double));
141 extern double exp __P((double));
142 extern double frexp __P((double, int *));
143 extern double ldexp __P((double, int));
144 extern double log __P((double));
145 extern double log10 __P((double));
146 extern double modf __P((double, double *));
148 extern double pow __P((double, double));
149 extern double sqrt __P((double));
151 extern double ceil __P((double));
152 extern double fabs __P((double));
153 extern double floor __P((double));
154 extern double fmod __P((double, double));
156 extern double erf __P((double));
157 extern double erfc __P((double));
158 extern double gamma __P((double));
159 extern double hypot __P((double, double));
162 #define isnan(x) ((x) != (x))
165 extern int finite __P((double));
166 extern double j0 __P((double));
167 extern double j1 __P((double));
168 extern double jn __P((int, double));
169 extern double lgamma __P((double));
170 extern double y0 __P((double));
171 extern double y1 __P((double));
172 extern double yn __P((int, double));
174 extern double acosh __P((double));
175 extern double asinh __P((double));
176 extern double atanh __P((double));
177 extern double cbrt __P((double));
178 extern double logb __P((double));
179 extern double nextafter __P((double, double));
180 extern double remainder __P((double, double));
182 extern double scalb __P((double, int));
184 extern double scalb __P((double, double));
187 extern int matherr __P((struct exception *));
192 extern double significand __P((double));
195 * Functions callable from C, intended to support IEEE arithmetic.
197 extern double copysign __P((double, double));
198 extern int ilogb __P((double));
199 extern double rint __P((double));
200 extern double scalbn __P((double, int));
203 * BSD math library entry points
205 extern double expm1 __P((double));
206 extern double log1p __P((double));
209 * Reentrant version of gamma & lgamma; passes signgam back by reference
210 * as the second argument; user must allocate space for signgam.
213 extern double gamma_r __P((double, int *));
214 extern double lgamma_r __P((double, int *));
215 #endif /* _REENTRANT */
217 /* ieee style elementary functions */
218 extern double __ieee754_sqrt __P((double));
219 extern double __ieee754_acos __P((double));
220 extern double __ieee754_acosh __P((double));
221 extern double __ieee754_log __P((double));
222 extern double __ieee754_atanh __P((double));
223 extern double __ieee754_asin __P((double));
224 extern double __ieee754_atan2 __P((double,double));
225 extern double __ieee754_exp __P((double));
226 extern double __ieee754_cosh __P((double));
227 extern double __ieee754_fmod __P((double,double));
228 extern double __ieee754_pow __P((double,double));
229 extern double __ieee754_lgamma_r __P((double,int *));
230 extern double __ieee754_gamma_r __P((double,int *));
231 extern double __ieee754_lgamma __P((double));
232 extern double __ieee754_gamma __P((double));
233 extern double __ieee754_log10 __P((double));
234 extern double __ieee754_sinh __P((double));
235 extern double __ieee754_hypot __P((double,double));
236 extern double __ieee754_j0 __P((double));
237 extern double __ieee754_j1 __P((double));
238 extern double __ieee754_y0 __P((double));
239 extern double __ieee754_y1 __P((double));
240 extern double __ieee754_jn __P((int,double));
241 extern double __ieee754_yn __P((int,double));
242 extern double __ieee754_remainder __P((double,double));
243 extern int32_t __ieee754_rem_pio2 __P((double,double*));
245 extern double __ieee754_scalb __P((double,int));
247 extern double __ieee754_scalb __P((double,double));
250 /* fdlibm kernel function */
251 extern double __kernel_standard __P((double,double,int));
252 extern double __kernel_sin __P((double,double,int));
253 extern double __kernel_cos __P((double,double));
254 extern double __kernel_tan __P((double,double,int));
255 extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
257 /* Classpath extensions */
259 /* The original code used statements like
260 n0 = ((*(int*)&one)>>29)^1; * index of high word *
261 ix0 = *(n0+(int*)&x); * high word of x *
262 ix1 = *((1-n0)+(int*)&x); * low word of x *
263 to dig two 32 bit words out of the 64 bit IEEE floating point
264 value. That is non-ANSI, and, moreover, the gcc instruction
265 scheduler gets it wrong. We instead use the following macros.
266 Unlike the original code, we determine the endianness at compile
267 time, not at run time; I don't see much benefit to selecting
268 endianness at run time. */
270 #ifndef __IEEE_BIG_ENDIAN
271 #ifndef __IEEE_LITTLE_ENDIAN
272 #error Must define endianness
276 /* A union which permits us to convert between a double and two 32 bit
279 #ifdef __IEEE_BIG_ENDIAN
289 } ieee_double_shape_type;
293 #ifdef __IEEE_LITTLE_ENDIAN
303 } ieee_double_shape_type;
307 /* Get two 32 bit ints from a double. */
309 #define EXTRACT_WORDS(ix0,ix1,d) \
311 ieee_double_shape_type ew_u; \
313 (ix0) = ew_u.parts.msw; \
314 (ix1) = ew_u.parts.lsw; \
317 /* Get the more significant 32 bit int from a double. */
319 #define GET_HIGH_WORD(i,d) \
321 ieee_double_shape_type gh_u; \
323 (i) = gh_u.parts.msw; \
326 /* Get the less significant 32 bit int from a double. */
328 #define GET_LOW_WORD(i,d) \
330 ieee_double_shape_type gl_u; \
332 (i) = gl_u.parts.lsw; \
335 /* Set a double from two 32 bit ints. */
337 #define INSERT_WORDS(d,ix0,ix1) \
339 ieee_double_shape_type iw_u; \
340 iw_u.parts.msw = (ix0); \
341 iw_u.parts.lsw = (ix1); \
345 /* Set the more significant 32 bits of a double from an int. */
347 #define SET_HIGH_WORD(d,v) \
349 ieee_double_shape_type sh_u; \
351 sh_u.parts.msw = (v); \
355 /* Set the less significant 32 bits of a double from an int. */
357 #define SET_LOW_WORD(d,v) \
359 ieee_double_shape_type sl_u; \
361 sl_u.parts.lsw = (v); \
365 /* A union which permits us to convert between a float and a 32 bit
372 } ieee_float_shape_type;
374 /* Get a 32 bit int from a float. */
376 #define GET_FLOAT_WORD(i,d) \
378 ieee_float_shape_type gf_u; \
383 /* Set a float from a 32 bit int. */
385 #define SET_FLOAT_WORD(d,i) \
387 ieee_float_shape_type sf_u; \
396 #endif /* __CLASSPATH_FDLIBM_H__ */