* src/boehm-gc/.cvsignore, src/boehm-gc/include/.cvsignore,
[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 #if !defined(isnan) && !defined(HAVE_ISNAN)
66 #define isnan(x) ((x) != (x))
67 #endif
68
69 /* ieee style elementary functions */
70 extern double __ieee754_fmod __P((double,double));
71
72 /*
73  * Functions callable from C, intended to support IEEE arithmetic.
74  */
75 extern double copysign __P((double, double));
76
77 /* The original code used statements like
78         n0 = ((*(int*)&one)>>29)^1;             * index of high word *
79         ix0 = *(n0+(int*)&x);                   * high word of x *
80         ix1 = *((1-n0)+(int*)&x);               * low word of x *
81    to dig two 32 bit words out of the 64 bit IEEE floating point
82    value.  That is non-ANSI, and, moreover, the gcc instruction
83    scheduler gets it wrong.  We instead use the following macros.
84    Unlike the original code, we determine the endianness at compile
85    time, not at run time; I don't see much benefit to selecting
86    endianness at run time.  */
87
88 #ifndef __IEEE_BIG_ENDIAN
89 #ifndef __IEEE_LITTLE_ENDIAN
90  #error Must define endianness
91 #endif
92 #endif
93
94 /* A union which permits us to convert between a double and two 32 bit
95    ints.  */
96
97 #ifdef __IEEE_BIG_ENDIAN
98
99 typedef union 
100 {
101   double value;
102   struct 
103   {
104     uint32_t msw;
105     uint32_t lsw;
106   } parts;
107 } ieee_double_shape_type;
108
109 #endif
110
111 #ifdef __IEEE_LITTLE_ENDIAN
112
113 typedef union 
114 {
115   double value;
116   struct 
117   {
118     uint32_t lsw;
119     uint32_t msw;
120   } parts;
121 } ieee_double_shape_type;
122
123 #endif
124
125 /* Get two 32 bit ints from a double.  */
126
127 #define EXTRACT_WORDS(ix0,ix1,d)                                \
128 do {                                                            \
129   ieee_double_shape_type ew_u;                                  \
130   ew_u.value = (d);                                             \
131   (ix0) = ew_u.parts.msw;                                       \
132   (ix1) = ew_u.parts.lsw;                                       \
133 } while (0)
134
135 /* Get the more significant 32 bit int from a double.  */
136
137 #define GET_HIGH_WORD(i,d)                                      \
138 do {                                                            \
139   ieee_double_shape_type gh_u;                                  \
140   gh_u.value = (d);                                             \
141   (i) = gh_u.parts.msw;                                         \
142 } while (0)
143
144 /* Get the less significant 32 bit int from a double.  */
145
146 #define GET_LOW_WORD(i,d)                                       \
147 do {                                                            \
148   ieee_double_shape_type gl_u;                                  \
149   gl_u.value = (d);                                             \
150   (i) = gl_u.parts.lsw;                                         \
151 } while (0)
152
153 /* Set a double from two 32 bit ints.  */
154
155 #define INSERT_WORDS(d,ix0,ix1)                                 \
156 do {                                                            \
157   ieee_double_shape_type iw_u;                                  \
158   iw_u.parts.msw = (ix0);                                       \
159   iw_u.parts.lsw = (ix1);                                       \
160   (d) = iw_u.value;                                             \
161 } while (0)
162
163 /* Set the more significant 32 bits of a double from an int.  */
164
165 #define SET_HIGH_WORD(d,v)                                      \
166 do {                                                            \
167   ieee_double_shape_type sh_u;                                  \
168   sh_u.value = (d);                                             \
169   sh_u.parts.msw = (v);                                         \
170   (d) = sh_u.value;                                             \
171 } while (0)
172
173 /* Set the less significant 32 bits of a double from an int.  */
174
175 #define SET_LOW_WORD(d,v)                                       \
176 do {                                                            \
177   ieee_double_shape_type sl_u;                                  \
178   sl_u.value = (d);                                             \
179   sl_u.parts.lsw = (v);                                         \
180   (d) = sl_u.value;                                             \
181 } while (0)
182
183 /* A union which permits us to convert between a float and a 32 bit
184    int.  */
185
186 typedef union
187 {
188   float value;
189   uint32_t word;
190 } ieee_float_shape_type;
191
192 /* Get a 32 bit int from a float.  */
193
194 #define GET_FLOAT_WORD(i,d)                                     \
195 do {                                                            \
196   ieee_float_shape_type gf_u;                                   \
197   gf_u.value = (d);                                             \
198   (i) = gf_u.word;                                              \
199 } while (0)
200
201 /* Set a float from a 32 bit int.  */
202
203 #define SET_FLOAT_WORD(d,i)                                     \
204 do {                                                            \
205   ieee_float_shape_type sf_u;                                   \
206   sf_u.word = (i);                                              \
207   (d) = sf_u.value;                                             \
208 } while (0)
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif /* __CLASSPATH_FDLIBM_H__ */