xref: /openbsd-src/gnu/gcc/libstdc++-v3/libmath/mathconf.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* Configuration data for libmath subpart of libstdc++. */
2*404b540aSrobert 
3*404b540aSrobert /* Copyright (C) 1997-1999, 2000, 2001 Free Software Foundation, Inc.
4*404b540aSrobert 
5*404b540aSrobert    This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert    software; you can redistribute it and/or modify it under the
7*404b540aSrobert    terms of the GNU General Public License as published by the
8*404b540aSrobert    Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert    any later version.
10*404b540aSrobert 
11*404b540aSrobert    This library is distributed in the hope that it will be useful,
12*404b540aSrobert    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert    GNU General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert    You should have received a copy of the GNU General Public License along
17*404b540aSrobert    with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert    USA.
20*404b540aSrobert 
21*404b540aSrobert    As a special exception, you may use this file as part of a free software
22*404b540aSrobert    library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert    templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert    this file and link it with other files to produce an executable, this
25*404b540aSrobert    file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert    the GNU General Public License.  This exception does not however
27*404b540aSrobert    invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert    the GNU General Public License.  */
29*404b540aSrobert 
30*404b540aSrobert 
31*404b540aSrobert #include <config.h>
32*404b540aSrobert 
33*404b540aSrobert #ifdef HAVE_ENDIAN_H
34*404b540aSrobert # include <endian.h>
35*404b540aSrobert #else
36*404b540aSrobert # ifdef HAVE_MACHINE_ENDIAN_H
37*404b540aSrobert #  ifdef HAVE_SYS_TYPES_H
38*404b540aSrobert #   include <sys/types.h>
39*404b540aSrobert #  endif
40*404b540aSrobert #  include <machine/endian.h>
41*404b540aSrobert # else
42*404b540aSrobert #  ifdef HAVE_SYS_MACHINE_H
43*404b540aSrobert #   include <sys/machine.h>
44*404b540aSrobert #  else
45*404b540aSrobert #   if defined HAVE_SYS_ISA_DEFS_H || defined HAVE_MACHINE_PARAM_H
46*404b540aSrobert /* This is on Solaris.  */
47*404b540aSrobert #    ifdef HAVE_SYS_ISA_DEFS_H
48*404b540aSrobert #     include <sys/isa_defs.h>
49*404b540aSrobert #    endif
50*404b540aSrobert #    ifdef HAVE_MACHINE_PARAM_H
51*404b540aSrobert #     include <machine/param.h>
52*404b540aSrobert #    endif
53*404b540aSrobert #    ifdef _LITTLE_ENDIAN
54*404b540aSrobert #     define LITTLE_ENDIAN 1
55*404b540aSrobert #    endif
56*404b540aSrobert #    ifdef _BIG_ENDIAN
57*404b540aSrobert #     define BIG_ENDIAN 1
58*404b540aSrobert #    endif
59*404b540aSrobert #    define BYTE_ORDER 1
60*404b540aSrobert #   else
61*404b540aSrobert /* We have to rely on the AC_C_BIGENDIAN test.  */
62*404b540aSrobert #    ifdef WORDS_BIGENDIAN
63*404b540aSrobert #     define BIG_ENDIAN 1
64*404b540aSrobert #    else
65*404b540aSrobert #     define LITTLE_ENDIAN 1
66*404b540aSrobert #    endif
67*404b540aSrobert #    define BYTE_ORDER 1
68*404b540aSrobert #   endif
69*404b540aSrobert #  endif
70*404b540aSrobert # endif
71*404b540aSrobert #endif
72*404b540aSrobert 
73*404b540aSrobert typedef unsigned int U_int32_t __attribute ((mode (SI)));
74*404b540aSrobert typedef int Int32_t __attribute ((mode (SI)));
75*404b540aSrobert typedef unsigned int U_int64_t __attribute ((mode (DI)));
76*404b540aSrobert typedef int Int64_t __attribute ((mode (DI)));
77*404b540aSrobert 
78*404b540aSrobert #ifdef HAVE_NAN_H
79*404b540aSrobert # include <nan.h>
80*404b540aSrobert #endif
81*404b540aSrobert 
82*404b540aSrobert #ifdef HAVE_IEEEFP_H
83*404b540aSrobert # include <ieeefp.h>
84*404b540aSrobert #endif
85*404b540aSrobert 
86*404b540aSrobert #ifdef HAVE_FP_H
87*404b540aSrobert # include <fp.h>
88*404b540aSrobert #endif
89*404b540aSrobert 
90*404b540aSrobert #ifdef HAVE_FLOAT_H
91*404b540aSrobert # include <float.h>
92*404b540aSrobert #endif
93*404b540aSrobert 
94*404b540aSrobert /* `float' variant of HUGE_VAL.  */
95*404b540aSrobert #ifndef HUGE_VALF
96*404b540aSrobert # ifdef HUGE_VALf
97*404b540aSrobert #  define HUGE_VALF HUGE_VALf
98*404b540aSrobert # else
99*404b540aSrobert #  define HUGE_VALF HUGE_VAL
100*404b540aSrobert # endif
101*404b540aSrobert #endif
102*404b540aSrobert 
103*404b540aSrobert /* `long double' variant of HUGE_VAL.  */
104*404b540aSrobert #ifndef HUGE_VALL
105*404b540aSrobert # ifdef HUGE_VALl
106*404b540aSrobert #  define HUGE_VALL HUGE_VALl
107*404b540aSrobert # else
108*404b540aSrobert #  define HUGE_VALL HUGE_VAL
109*404b540aSrobert # endif
110*404b540aSrobert #endif
111*404b540aSrobert 
112*404b540aSrobert /* Make sure that at least HUGE_VAL is defined.  */
113*404b540aSrobert #ifndef HUGE_VAL
114*404b540aSrobert # ifdef HUGE
115*404b540aSrobert #  define HUGE_VAL HUGE
116*404b540aSrobert # else
117*404b540aSrobert #  ifdef MAXFLOAT
118*404b540aSrobert #   define HUGE_VAL MAXFLOAT
119*404b540aSrobert #  else
120*404b540aSrobert #   error "We need HUGE_VAL!"
121*404b540aSrobert #  endif
122*404b540aSrobert # endif
123*404b540aSrobert #endif
124*404b540aSrobert 
125*404b540aSrobert #ifndef M_PI
126*404b540aSrobert # define M_PI 3.14159265358979323846
127*404b540aSrobert #endif
128*404b540aSrobert 
129*404b540aSrobert 
130*404b540aSrobert #ifdef __cplusplus
131*404b540aSrobert extern "C" {
132*404b540aSrobert #endif
133*404b540aSrobert 
134*404b540aSrobert /* signbit is a macro in ISO C99.  */
135*404b540aSrobert #ifndef signbit
136*404b540aSrobert extern int __signbitf (float);
137*404b540aSrobert extern int __signbit (double);
138*404b540aSrobert extern int __signbitl (long double);
139*404b540aSrobert 
140*404b540aSrobert # define signbit(x) \
141*404b540aSrobert      (sizeof (x) == sizeof (float) ?                                          \
142*404b540aSrobert         __signbitf (x)                                                        \
143*404b540aSrobert       : sizeof (x) == sizeof (double) ?                                       \
144*404b540aSrobert         __signbit (x) : __signbitl (x))
145*404b540aSrobert #endif
146*404b540aSrobert 
147*404b540aSrobert #if BYTE_ORDER == BIG_ENDIAN
148*404b540aSrobert typedef union
149*404b540aSrobert {
150*404b540aSrobert   double value;
151*404b540aSrobert   struct
152*404b540aSrobert   {
153*404b540aSrobert     U_int32_t msw;
154*404b540aSrobert     U_int32_t lsw;
155*404b540aSrobert   } parts;
156*404b540aSrobert } ieee_double_shape_type;
157*404b540aSrobert #endif
158*404b540aSrobert #if BYTE_ORDER == LITTLE_ENDIAN
159*404b540aSrobert typedef union
160*404b540aSrobert {
161*404b540aSrobert   double value;
162*404b540aSrobert   struct
163*404b540aSrobert   {
164*404b540aSrobert     U_int32_t lsw;
165*404b540aSrobert     U_int32_t msw;
166*404b540aSrobert   } parts;
167*404b540aSrobert } ieee_double_shape_type;
168*404b540aSrobert #endif
169*404b540aSrobert /* Get the more significant 32 bit int from a double.  */
170*404b540aSrobert #define GET_HIGH_WORD(i,d)                                      \
171*404b540aSrobert do {                                                            \
172*404b540aSrobert   ieee_double_shape_type gh_u;                                  \
173*404b540aSrobert   gh_u.value = (d);                                             \
174*404b540aSrobert   (i) = gh_u.parts.msw;                                         \
175*404b540aSrobert } while (0)
176*404b540aSrobert 
177*404b540aSrobert 
178*404b540aSrobert typedef union
179*404b540aSrobert {
180*404b540aSrobert   float value;
181*404b540aSrobert   U_int32_t word;
182*404b540aSrobert } ieee_float_shape_type;
183*404b540aSrobert /* Get a 32 bit int from a float.  */
184*404b540aSrobert #define GET_FLOAT_WORD(i,d)                                     \
185*404b540aSrobert do {                                                            \
186*404b540aSrobert   ieee_float_shape_type gf_u;                                   \
187*404b540aSrobert   gf_u.value = (d);                                             \
188*404b540aSrobert   (i) = gf_u.word;                                              \
189*404b540aSrobert } while (0)
190*404b540aSrobert 
191*404b540aSrobert 
192*404b540aSrobert #if BYTE_ORDER == BIG_ENDIAN
193*404b540aSrobert typedef union
194*404b540aSrobert {
195*404b540aSrobert   long double value;
196*404b540aSrobert   struct
197*404b540aSrobert   {
198*404b540aSrobert     unsigned int sign_exponent:16;
199*404b540aSrobert     unsigned int empty:16;
200*404b540aSrobert     U_int32_t msw;
201*404b540aSrobert     U_int32_t lsw;
202*404b540aSrobert   } parts;
203*404b540aSrobert } ieee_long_double_shape_type;
204*404b540aSrobert #endif
205*404b540aSrobert #if BYTE_ORDER == LITTLE_ENDIAN
206*404b540aSrobert typedef union
207*404b540aSrobert {
208*404b540aSrobert   long double value;
209*404b540aSrobert   struct
210*404b540aSrobert   {
211*404b540aSrobert     U_int32_t lsw;
212*404b540aSrobert     U_int32_t msw;
213*404b540aSrobert     unsigned int sign_exponent:16;
214*404b540aSrobert     unsigned int empty:16;
215*404b540aSrobert   } parts;
216*404b540aSrobert } ieee_long_double_shape_type;
217*404b540aSrobert #endif
218*404b540aSrobert /* Get int from the exponent of a long double.  */
219*404b540aSrobert #define GET_LDOUBLE_EXP(exp,d)                                  \
220*404b540aSrobert do {                                                            \
221*404b540aSrobert   ieee_long_double_shape_type ge_u;                             \
222*404b540aSrobert   ge_u.value = (d);                                             \
223*404b540aSrobert   (exp) = ge_u.parts.sign_exponent;                             \
224*404b540aSrobert } while (0)
225*404b540aSrobert 
226*404b540aSrobert #if BYTE_ORDER == BIG_ENDIAN
227*404b540aSrobert typedef union
228*404b540aSrobert {
229*404b540aSrobert   long double value;
230*404b540aSrobert   struct
231*404b540aSrobert   {
232*404b540aSrobert     U_int64_t msw;
233*404b540aSrobert     U_int64_t lsw;
234*404b540aSrobert   } parts64;
235*404b540aSrobert   struct
236*404b540aSrobert   {
237*404b540aSrobert     U_int32_t w0, w1, w2, w3;
238*404b540aSrobert   } parts32;
239*404b540aSrobert } ieee_quad_double_shape_type;
240*404b540aSrobert #endif
241*404b540aSrobert #if BYTE_ORDER == LITTLE_ENDIAN
242*404b540aSrobert typedef union
243*404b540aSrobert {
244*404b540aSrobert   long double value;
245*404b540aSrobert   struct
246*404b540aSrobert   {
247*404b540aSrobert     U_int64_t lsw;
248*404b540aSrobert     U_int64_t msw;
249*404b540aSrobert   } parts64;
250*404b540aSrobert   struct
251*404b540aSrobert   {
252*404b540aSrobert     U_int32_t w3, w2, w1, w0;
253*404b540aSrobert   } parts32;
254*404b540aSrobert } ieee_quad_double_shape_type;
255*404b540aSrobert #endif
256*404b540aSrobert /* Get most significant 64 bit int from a quad long double.  */
257*404b540aSrobert #define GET_LDOUBLE_MSW64(msw,d)				\
258*404b540aSrobert do {								\
259*404b540aSrobert   ieee_quad_double_shape_type qw_u;				\
260*404b540aSrobert   qw_u.value = (d);						\
261*404b540aSrobert   (msw) = qw_u.parts64.msw;					\
262*404b540aSrobert } while (0)
263*404b540aSrobert 
264*404b540aSrobert 
265*404b540aSrobert /* Replacement for non-existing float functions.  */
266*404b540aSrobert #if !defined(HAVE_FABSF) && !defined(HAVE___BUILTIN_FABSF)
267*404b540aSrobert # define fabsf(x) fabs (x)
268*404b540aSrobert #endif
269*404b540aSrobert #if !defined(HAVE_COSF) && !defined(HAVE___BUILTIN_COSF)
270*404b540aSrobert # define cosf(x) cos (x)
271*404b540aSrobert #endif
272*404b540aSrobert #ifndef HAVE_COSHF
273*404b540aSrobert # define coshf(x) cosh (x)
274*404b540aSrobert #endif
275*404b540aSrobert #ifndef HAVE_EXPF
276*404b540aSrobert # define expf(x) expf (x)
277*404b540aSrobert #endif
278*404b540aSrobert #ifndef HAVE_LOGF
279*404b540aSrobert # define logf(x) log(x)
280*404b540aSrobert #endif
281*404b540aSrobert #ifndef HAVE_LOG10F
282*404b540aSrobert # define log10f(x) log10 (x)
283*404b540aSrobert #endif
284*404b540aSrobert #ifndef HAVE_POWF
285*404b540aSrobert # define powf(x, y) pow (x, y)
286*404b540aSrobert #endif
287*404b540aSrobert #if !defined(HAVE_SINF) && !defined(HAVE___BUILTIN_SINF)
288*404b540aSrobert # define sinf(x) sin (x)
289*404b540aSrobert #endif
290*404b540aSrobert #ifndef HAVE_SINHF
291*404b540aSrobert # define sinhf(x) sinh (x)
292*404b540aSrobert #endif
293*404b540aSrobert #if !defined(HAVE_SQRTF) && !defined(HAVE___BUILTIN_SQRTF)
294*404b540aSrobert # define sqrtf(x) sqrt (x)
295*404b540aSrobert #endif
296*404b540aSrobert #ifndef HAVE_TANF
297*404b540aSrobert # define tanf(x) tan (x)
298*404b540aSrobert #endif
299*404b540aSrobert #ifndef HAVE_TANHF
300*404b540aSrobert # define tanhf(x) tanh (x)
301*404b540aSrobert #endif
302*404b540aSrobert #ifndef HAVE_STRTOF
303*404b540aSrobert # define strtof(s, e) strtod (s, e)
304*404b540aSrobert #endif
305*404b540aSrobert 
306*404b540aSrobert #ifdef __cplusplus
307*404b540aSrobert }
308*404b540aSrobert #endif
309*404b540aSrobert 
310