1/* Configuration data for libmath subpart of libstdc++. */
2
3/* Copyright (C) 1997-1999, 2000, 2001 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 <config.h>
32
33#ifdef HAVE_ENDIAN_H
34# include <endian.h>
35#else
36# ifdef HAVE_MACHINE_ENDIAN_H
37#  ifdef HAVE_SYS_TYPES_H
38#   include <sys/types.h>
39#  endif
40#  include <machine/endian.h>
41# else
42#  ifdef HAVE_SYS_MACHINE_H
43#   include <sys/machine.h>
44#  else
45#   if defined HAVE_SYS_ISA_DEFS_H || defined HAVE_MACHINE_PARAM_H
46/* This is on Solaris.  */
47#    ifdef HAVE_SYS_ISA_DEFS_H
48#     include <sys/isa_defs.h>
49#    endif
50#    ifdef HAVE_MACHINE_PARAM_H
51#     include <machine/param.h>
52#    endif
53#    ifdef _LITTLE_ENDIAN
54#     define LITTLE_ENDIAN 1
55#    endif
56#    ifdef _BIG_ENDIAN
57#     define BIG_ENDIAN 1
58#    endif
59#    define BYTE_ORDER 1
60#   else
61/* We have to rely on the AC_C_BIGENDIAN test.  */
62#    ifdef WORDS_BIGENDIAN
63#     define BIG_ENDIAN 1
64#    else
65#     define LITTLE_ENDIAN 1
66#    endif
67#    define BYTE_ORDER 1
68#   endif
69#  endif
70# endif
71#endif
72
73typedef unsigned int U_int32_t __attribute ((mode (SI)));
74typedef int Int32_t __attribute ((mode (SI)));
75typedef unsigned int U_int64_t __attribute ((mode (DI)));
76typedef int Int64_t __attribute ((mode (DI)));
77
78#ifdef HAVE_NAN_H
79# include <nan.h>
80#endif
81
82#ifndef NAN
83# define NAN (nan())
84double nan (void);
85#endif
86
87#ifdef HAVE_IEEEFP_H
88# include <ieeefp.h>
89#endif
90
91#ifdef HAVE_FP_H
92# include <fp.h>
93#endif
94
95#ifdef HAVE_FLOAT_H
96# include <float.h>
97#endif
98
99/* `float' variant of HUGE_VAL.  */
100#ifndef HUGE_VALF
101# ifdef HUGE_VALf
102#  define HUGE_VALF HUGE_VALf
103# else
104#  define HUGE_VALF HUGE_VAL
105# endif
106#endif
107
108/* `long double' variant of HUGE_VAL.  */
109#ifndef HUGE_VALL
110# ifdef HUGE_VALl
111#  define HUGE_VALL HUGE_VALl
112# else
113#  define HUGE_VALL HUGE_VAL
114# endif
115#endif
116
117/* Make sure that at least HUGE_VAL is defined.  */
118#ifndef HUGE_VAL
119# ifdef HUGE
120#  define HUGE_VAL HUGE
121# else
122#  ifdef MAXFLOAT
123#   define HUGE_VAL MAXFLOAT
124#  else
125#   error "We need HUGE_VAL!"
126#  endif
127# endif
128#endif
129
130#ifndef M_PI
131# define M_PI 3.14159265358979323846
132#endif
133
134
135#ifdef __cplusplus
136extern "C" {
137#endif
138
139/* signbit is a macro in ISO C99.  */
140#ifndef signbit
141extern int __signbitf (float);
142extern int __signbit (double);
143extern int __signbitl (long double);
144
145# define signbit(x) \
146     (sizeof (x) == sizeof (float) ?                                          \
147        __signbitf (x)                                                        \
148      : sizeof (x) == sizeof (double) ?                                       \
149        __signbit (x) : __signbitl (x))
150#endif
151
152#if BYTE_ORDER == BIG_ENDIAN
153typedef union
154{
155  double value;
156  struct
157  {
158    U_int32_t msw;
159    U_int32_t lsw;
160  } parts;
161} ieee_double_shape_type;
162#endif
163#if BYTE_ORDER == LITTLE_ENDIAN
164typedef union
165{
166  double value;
167  struct
168  {
169    U_int32_t lsw;
170    U_int32_t msw;
171  } parts;
172} ieee_double_shape_type;
173#endif
174/* Get the more significant 32 bit int from a double.  */
175#define GET_HIGH_WORD(i,d)                                      \
176do {                                                            \
177  ieee_double_shape_type gh_u;                                  \
178  gh_u.value = (d);                                             \
179  (i) = gh_u.parts.msw;                                         \
180} while (0)
181
182
183typedef union
184{
185  float value;
186  U_int32_t word;
187} ieee_float_shape_type;
188/* Get a 32 bit int from a float.  */
189#define GET_FLOAT_WORD(i,d)                                     \
190do {                                                            \
191  ieee_float_shape_type gf_u;                                   \
192  gf_u.value = (d);                                             \
193  (i) = gf_u.word;                                              \
194} while (0)
195
196
197#if BYTE_ORDER == BIG_ENDIAN
198typedef union
199{
200  long double value;
201  struct
202  {
203    unsigned int sign_exponent:16;
204    unsigned int empty:16;
205    U_int32_t msw;
206    U_int32_t lsw;
207  } parts;
208} ieee_long_double_shape_type;
209#endif
210#if BYTE_ORDER == LITTLE_ENDIAN
211typedef union
212{
213  long double value;
214  struct
215  {
216    U_int32_t lsw;
217    U_int32_t msw;
218    unsigned int sign_exponent:16;
219    unsigned int empty:16;
220  } parts;
221} ieee_long_double_shape_type;
222#endif
223/* Get int from the exponent of a long double.  */
224#define GET_LDOUBLE_EXP(exp,d)                                  \
225do {                                                            \
226  ieee_long_double_shape_type ge_u;                             \
227  ge_u.value = (d);                                             \
228  (exp) = ge_u.parts.sign_exponent;                             \
229} while (0)
230
231#if BYTE_ORDER == BIG_ENDIAN
232typedef union
233{
234  long double value;
235  struct
236  {
237    U_int64_t msw;
238    U_int64_t lsw;
239  } parts64;
240  struct
241  {
242    U_int32_t w0, w1, w2, w3;
243  } parts32;
244} ieee_quad_double_shape_type;
245#endif
246#if BYTE_ORDER == LITTLE_ENDIAN
247typedef union
248{
249  long double value;
250  struct
251  {
252    U_int64_t lsw;
253    U_int64_t msw;
254  } parts64;
255  struct
256  {
257    U_int32_t w3, w2, w1, w0;
258  } parts32;
259} ieee_quad_double_shape_type;
260#endif
261/* Get most significant 64 bit int from a quad long double.  */
262#define GET_LDOUBLE_MSW64(msw,d)				\
263do {								\
264  ieee_quad_double_shape_type qw_u;				\
265  qw_u.value = (d);						\
266  (msw) = qw_u.parts64.msw;					\
267} while (0)
268
269
270/* Replacement for non-existing float functions.  */
271#if !defined(HAVE_FABSF) && !defined(HAVE___BUILTIN_FABSF)
272# define fabsf(x) fabs (x)
273#endif
274#if !defined(HAVE_COSF) && !defined(HAVE___BUILTIN_COSF)
275# define cosf(x) cos (x)
276#endif
277#ifndef HAVE_COSHF
278# define coshf(x) cosh (x)
279#endif
280#ifndef HAVE_EXPF
281# define expf(x) expf (x)
282#endif
283#ifndef HAVE_LOGF
284# define logf(x) log(x)
285#endif
286#ifndef HAVE_LOG10F
287# define log10f(x) log10 (x)
288#endif
289#ifndef HAVE_POWF
290# define powf(x, y) pow (x, y)
291#endif
292#if !defined(HAVE_SINF) && !defined(HAVE___BUILTIN_SINF)
293# define sinf(x) sin (x)
294#endif
295#ifndef HAVE_SINHF
296# define sinhf(x) sinh (x)
297#endif
298#if !defined(HAVE_SQRTF) && !defined(HAVE___BUILTIN_SQRTF)
299# define sqrtf(x) sqrt (x)
300#endif
301#ifndef HAVE_TANF
302# define tanf(x) tan (x)
303#endif
304#ifndef HAVE_TANHF
305# define tanhf(x) tanh (x)
306#endif
307#ifndef HAVE_STRTOF
308# define strtof(s, e) strtod (s, e)
309#endif
310
311#ifdef __cplusplus
312}
313#endif
314
315