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