OSDN Git Service

c66fca7e0bf2966e8a54912febdc4b796a0bd253
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libmath / mathconf.h
1 /* Configuration data for libmath subpart of libstdc++. */
2
3 /* Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
4
5    This file is part of the GNU ISO C++ Library.  This library is free
6    software; you can redistribute it and/or modify it under the
7    terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License along
17    with this library; see the file COPYING.  If not, write to the Free
18    Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19    USA.
20
21    As a special exception, you may use this file as part of a free software
22    library without restriction.  Specifically, if other files instantiate
23    templates or use macros or inline functions from this file, or you compile
24    this file and link it with other files to produce an executable, this
25    file does not by itself cause the resulting executable to be covered by
26    the GNU General Public License.  This exception does not however
27    invalidate any other reasons why the executable file might be covered by
28    the GNU General Public License.  */
29
30
31 #include <bits/c++config.h>
32
33 #ifdef _GLIBCPP_HAVE_ENDIAN_H
34 # include <endian.h>
35 #else
36 # ifdef _GLIBCPP_HAVE_MACHINE_ENDIAN_H
37 #  include <machine/endian.h>
38 # else
39 #  ifdef _GLIBCPP_HAVE_SYS_MACHINE_H
40 #   include <sys/machine.h>
41 #  else
42 #   if defined _GLIBCPP_HAVE_SYS_ISA_DEFS_H || defined _GLIBCPP_HAVE_MACHINE_PARAM_H
43 /* This is on Solaris.  */
44 #    ifdef _GLIBCPP_HAVE_SYS_ISA_DEFS_H
45 #     include <sys/isa_defs.h>
46 #    endif
47 #    ifdef _GLIBCPP_HAVE_MACHINE_PARAM_H
48 #     include <machine/param.h>
49 #    endif
50 #    ifdef _LITTLE_ENDIAN
51 #     define LITTLE_ENDIAN 1
52 #    endif
53 #    ifdef _BIG_ENDIAN
54 #     define BIG_ENDIAN 1
55 #    endif
56 #    define BYTE_ORDER 1
57 #   else
58 /* We have to rely on the AC_C_BIGENDIAN test.  */
59 #    ifdef WORDS_BIGENDIAN
60 #     define BIG_ENDIAN 1
61 #    else
62 #     define LITTLE_ENDIAN 1
63 #    endif
64 #    define BYTE_ORDER 1
65 #   endif
66 #  endif
67 # endif
68 #endif
69
70 typedef unsigned int U_int32_t __attribute ((mode (SI)));
71 typedef int Int32_t __attribute ((mode (SI)));
72 typedef unsigned int U_int64_t __attribute ((mode (DI)));
73 typedef int Uint64_t __attribute ((mode (DI)));
74
75 #ifdef _GLIBCPP_HAVE_NAN_H
76 # include <nan.h>
77 #endif
78
79 #ifndef NAN
80 # define NAN (nan())
81 double nan (void);
82 #endif
83
84 #ifdef _GLIBCPP_HAVE_IEEEFP_H
85 # include <ieeefp.h>
86 #endif
87
88 #ifdef _GLIBCPP_HAVE_FP_H
89 # include <fp.h>
90 #endif
91
92 #ifdef _GLIBCPP_HAVE_FLOAT_H
93 # include <float.h>
94 #endif
95
96 /* `float' variant of HUGE_VAL.  */
97 #ifndef HUGE_VALF
98 # ifdef HUGE_VALf
99 #  define HUGE_VALF HUGE_VALf
100 # else
101 #  define HUGE_VALF HUGE_VAL
102 # endif
103 #endif
104
105 /* `long double' variant of HUGE_VAL.  */
106 #ifndef HUGE_VALL
107 # ifdef HUGE_VALl
108 #  define HUGE_VALL HUGE_VALl
109 # else
110 #  define HUGE_VALL HUGE_VAL
111 # endif
112 #endif
113
114 /* Make sure that at least HUGE_VAL is defined.  */
115 #ifndef HUGE_VAL
116 # ifdef HUGE
117 #  define HUGE_VAL HUGE
118 # else
119 #  ifdef MAXFLOAT
120 #   define HUGE_VAL MAXFLOAT
121 #  else
122 #   error "We need HUGE_VAL!"
123 #  endif
124 # endif
125 #endif
126
127 #ifndef M_PI
128 # define M_PI 3.14159265358979323846
129 #endif
130
131 /* Test whether number is finite.  */
132 #ifdef isfinite
133 /* This is an ISO C99 function.  */
134 # define FINITE_P(X) isfinite (X)
135 # define FINITEF_P(X) isfinite (X)
136 # define FINITEL_P(X) isfinite (X)
137 #else
138 # ifdef IsNANorINF
139 /* This is for Solaris, which does not have special macros for other
140    types.  */
141 #  define FINITE_P(X) (!IsNANorINF (X))
142 #  define FINITEF_P(X) (!IsNANorINF (X))
143 #  define FINITEL_P(X) (!IsNANorINF (X))
144 # else
145 #  if defined _GLIBCPP_HAVE_ISINF && defined _GLIBCPP_HAVE_ISNAN
146 #   define FINITE_P(X) ({ double __x = (X); !isinf (__x) && !isnan (__x); })
147 #  else
148 #   ifdef _GLIBCPP_HAVE_FINITE
149 #    define FINITE_P(X) finite (X)
150 #   else
151 #    error "We need FINITE_P"
152 #   endif
153 #  endif
154 #  if defined _GLIBCPP_HAVE_ISINFF && defined _GLIBCPP_HAVE_ISNANF
155 #   define FINITEF_P(X) ({ float __x = (X); !isinff (__x) && !isnanf (__x); })
156 #  else
157 #   ifdef _GLIBCPP_HAVE_FINITE
158 #    define FINITEF_P(X) finite (X)
159 #   else
160 #    define FINITEF_P(X) FINITE_P (X)
161 #   endif
162 #  endif
163 #  if defined _GLIBCPP_HAVE_ISINFL && defined _GLIBCPP_HAVE_ISNANL
164 #   define FINITEL_P(X) ({ long double __x = (X); \
165                            !isinfl (__x) && !isnanl (__x); })
166 #  else
167 #   ifdef _GLIBCPP_HAVE_QFINITE
168 #    define FINITEL_P(X) qfinite (X)
169 #   else
170 #    define FINITEL_P(X) FINITE_P (X)
171 #   endif
172 #  endif
173 # endif
174 #endif
175
176 /* Test whether number is infinite.  */
177 #ifdef isinf
178 /* This is an ISO C99 macro.  */
179 # define INFINITE_P(X) isinf (X)
180 # define INFINITEF_P(X) isinf (X)
181 # define INFINITEL_P(X) isinf (X)
182 #else
183 # ifdef IsINF
184 /* This is for Solaris, which does not have special macros for other
185    types.  */
186 #  define INFINITE_P(X) IsINF (X)
187 #  define INFINITEF_P(X) IsINF (X)
188 #  define INFINITEL_P(X) IsINF (X)
189 # else
190 #  if defined _GLIBCPP_HAVE_ISINF
191 #   define INFINITE_P(X) isinf (X)
192 #  else
193 #   ifdef _GLIBCPP_HAVE_FPCLASS
194 #    ifdef _FPCLASS_PINF
195 /* Mingw defines _FPCLASS_PINF.  */
196 #     define FP_PINF _FPCLASS_PINF
197 #    endif
198 /* This is for Irix and Mingw.  */
199 #    define INFINITE_P(X) (fpclass (fabs (X)) == FP_PINF)
200 #   else
201 #    ifdef IS_INF
202 /* This is for AIX.  */
203 #     define INFINITE_P(X) ({ double __d = (X); IS_INF (__d); })
204 #    else
205 #     error "We need INFINITE_P"
206 #    endif
207 #   endif
208 #  endif
209 #  if defined _GLIBCPP_HAVE_ISINFF
210 #   define INFINITEF_P(X) isinff (X)
211 #  else
212 #   define INFINITEF_P(X) INFINITE_P (X)
213 #  endif
214 #  if defined _GLIBCPP_HAVE_ISINFL
215 #   define INFINITEL_P(X) isinfl (X)
216 #  else
217 #   ifdef _GLIBCPP_HAVE_QFPCLASS
218 #    define INFINITEL_P(X) (qfpclass (fabsl (X)) == FP_PINF)
219 #   else
220 #    define INFINITEL_P(X) INFINITE_P (X)
221 #   endif
222 #  endif
223 # endif
224 #endif
225
226 #ifdef __cplusplus
227 extern "C" {
228 #endif
229
230 /* signbit is a macro in ISO C99.  */
231 #ifndef signbit
232 extern int __signbitf (float);
233 extern int __signbit (double);
234 extern int __signbitl (long double);
235
236 # define signbit(x) \
237      (sizeof (x) == sizeof (float) ?                                          \
238         __signbitf (x)                                                        \
239       : sizeof (x) == sizeof (double) ?                                       \
240         __signbit (x) : __signbitl (x))
241 #endif
242
243 #if BYTE_ORDER == BIG_ENDIAN
244 typedef union
245 {
246   double value;
247   struct
248   {
249     U_int32_t msw;
250     U_int32_t lsw;
251   } parts;
252 } ieee_double_shape_type;
253 #endif
254 #if BYTE_ORDER == LITTLE_ENDIAN
255 typedef union
256 {
257   double value;
258   struct
259   {
260     U_int32_t lsw;
261     U_int32_t msw;
262   } parts;
263 } ieee_double_shape_type;
264 #endif
265 /* Get the more significant 32 bit int from a double.  */
266 #define GET_HIGH_WORD(i,d)                                      \
267 do {                                                            \
268   ieee_double_shape_type gh_u;                                  \
269   gh_u.value = (d);                                             \
270   (i) = gh_u.parts.msw;                                         \
271 } while (0)
272
273
274 typedef union
275 {
276   float value;
277   U_int32_t word;
278 } ieee_float_shape_type;
279 /* Get a 32 bit int from a float.  */
280 #define GET_FLOAT_WORD(i,d)                                     \
281 do {                                                            \
282   ieee_float_shape_type gf_u;                                   \
283   gf_u.value = (d);                                             \
284   (i) = gf_u.word;                                              \
285 } while (0)
286
287
288 #if BYTE_ORDER == BIG_ENDIAN
289 typedef union
290 {
291   long double value;
292   struct
293   {
294     unsigned int sign_exponent:16;
295     unsigned int empty:16;
296     U_int32_t msw;
297     U_int32_t lsw;
298   } parts;
299 } ieee_long_double_shape_type;
300 #endif
301 #if BYTE_ORDER == LITTLE_ENDIAN
302 typedef union
303 {
304   long double value;
305   struct
306   {
307     U_int32_t lsw;
308     U_int32_t msw;
309     unsigned int sign_exponent:16;
310     unsigned int empty:16;
311   } parts;
312 } ieee_long_double_shape_type;
313 #endif
314 /* Get int from the exponent of a long double.  */
315 #define GET_LDOUBLE_EXP(exp,d)                                  \
316 do {                                                            \
317   ieee_long_double_shape_type ge_u;                             \
318   ge_u.value = (d);                                             \
319   (exp) = ge_u.parts.sign_exponent;                             \
320 } while (0)
321
322 #if BYTE_ORDER == BIG_ENDIAN
323 typedef union
324 {
325   long double value;
326   struct
327   {
328     U_int64_t msw;
329     U_int64_t lsw;
330   } parts64;
331   struct
332   {
333     U_int32_t w0, w1, w2, w3;
334   } parts32;
335 } ieee_quad_double_shape_type;
336 #endif
337 #if BYTE_ORDER == LITTLE_ENDIAN
338 typedef union
339 {
340   long double value;
341   struct
342   {
343     U_int64_t lsw;
344     U_int64_t msw;
345   } parts64;
346   struct
347   {
348     U_int32_t w3, w2, w1, w0;
349   } parts32;
350 } ieee_quad_double_shape_type;
351 #endif
352 /* Get most significant 64 bit int from a quad long double.  */
353 #define GET_LDOUBLE_MSW64(msw,d)                                \
354 do {                                                            \
355   ieee_quad_double_shape_type qw_u;                             \
356   qw_u.value = (d);                                             \
357   (ix0) = qw_u.parts64.msw;                                     \
358 } while (0)
359         
360
361 /* Replacement for non-existing float functions.  */
362 #if !defined(_GLIBCPP_HAVE_FABSF) && !defined(_GLIBCPP_HAVE___BUILTIN_FABSF)
363 # define fabsf(x) fabs (x)
364 #endif
365 #if !defined(_GLIBCPP_HAVE_COSF) && !defined(_GLIBCPP_HAVE___BUILTIN_COSF)
366 # define cosf(x) cos (x)
367 #endif
368 #ifndef _GLIBCPP_HAVE_COSHF
369 # define coshf(x) cosh (x)
370 #endif
371 #ifndef _GLIBCPP_HAVE_EXPF
372 # define expf(x) expf (x)
373 #endif
374 #ifndef _GLIBCPP_HAVE_LOGF
375 # define logf(x) log(x)
376 #endif
377 #ifndef _GLIBCPP_HAVE_LOG10F
378 # define log10f(x) log10 (x)
379 #endif
380 #ifndef _GLIBCPP_HAVE_POWF
381 # define powf(x, y) pow (x, y)
382 #endif
383 #if !defined(_GLIBCPP_HAVE_SINF) && !defined(_GLIBCPP_HAVE___BUILTIN_SINF)
384 # define sinf(x) sin (x)
385 #endif
386 #ifndef _GLIBCPP_HAVE_SINHF
387 # define sinhf(x) sinh (x)
388 #endif
389 #if !defined(_GLIBCPP_HAVE_SQRTF) && !defined(_GLIBCPP_HAVE___BUILTIN_SQRTF)
390 # define sqrtf(x) sqrt (x)
391 #endif
392 #ifndef _GLIBCPP_HAVE_TANF
393 # define tanf(x) tan (x)
394 #endif
395 #ifndef _GLIBCPP_HAVE_TANHF
396 # define tanhf(x) tanh (x)
397 #endif
398 #ifndef _GLIBCPP_HAVE_STRTOF
399 # define strtof(s, e) strtod (s, e)
400 #endif
401
402 #ifdef __cplusplus
403 }
404 #endif