this repo has no description
at fixPythonPipStalling 883 lines 39 kB view raw
1/* 2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * The contents of this file constitute Original Code as defined in and 7 * are subject to the Apple Public Source License Version 1.1 (the 8 * "License"). You may not use this file except in compliance with the 9 * License. Please obtain a copy of the License at 10 * http://www.apple.com/publicsource and read it before using this file. 11 * 12 * This Original Code and all software distributed under the License are 13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 * License for the specific language governing rights and limitations 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22 23/******************************************************************************* 24* * 25* File: math.h * 26* * 27* Contains: typedefs, prototypes, and macros germane to C99 floating point.* 28* * 29*******************************************************************************/ 30#ifndef __MATH__ 31#define __MATH__ 32 33#include "sys/cdefs.h" /* For definition of __DARWIN_UNIX03 et al */ 34 35#if (!defined(__WANT_LONG_DOUBLE_FORMAT__)) 36#if defined(__APPLE_CC__) && defined(__LONG_DOUBLE_128__) 37#define __WANT_LONG_DOUBLE_FORMAT__ 128 38#else 39#define __WANT_LONG_DOUBLE_FORMAT__ 64 40#endif 41#endif 42 43#if ( __WANT_LONG_DOUBLE_FORMAT__ - 0L == 128L ) 44#define __LIBMLDBL_COMPAT(sym) __asm("_" __STRING(sym) "$LDBL128") 45#elif ( __WANT_LONG_DOUBLE_FORMAT__ - 0L == 64L ) 46#define __LIBMLDBL_COMPAT(sym) /* NOTHING */ 47#else 48#define __LIBMLDBL_COMPAT(sym) /* NOTHING */ 49#endif 50 51#ifdef __cplusplus 52extern "C" { 53#endif 54 55/****************************************************************************** 56* Floating point data types * 57******************************************************************************/ 58 59/* Define float_t and double_t per C standard, ISO/IEC 9899:1999 7.12 2, 60 taking advantage of GCC's __FLT_EVAL_METHOD__ (which a compiler may 61 define anytime and GCC does) that shadows FLT_EVAL_METHOD (which a compiler 62 must and may define only in float.h). 63*/ 64#if __FLT_EVAL_METHOD__ == 0 65 typedef float float_t; 66 typedef double double_t; 67#elif __FLT_EVAL_METHOD__ == 1 68 typedef double float_t; 69 typedef double double_t; 70#elif __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ == -1 71 typedef long double float_t; 72 typedef long double double_t; 73#else /* __FLT_EVAL_METHOD__ */ 74 #error "Unsupported value of __FLT_EVAL_METHOD__." 75#endif /* __FLT_EVAL_METHOD__ */ 76 77 78#if defined(__GNUC__) && ! defined( __XLC__ ) 79 #define HUGE_VAL __builtin_huge_val() 80 #define HUGE_VALF __builtin_huge_valf() 81 #define HUGE_VALL __builtin_huge_vall() 82 #define NAN __builtin_nanf("0x7fc00000") /* Constant expression, can be used as initializer. */ 83 #define __MATH_H_ALWAYS_INLINE__ __attribute__ ((always_inline)) 84#else 85 #define HUGE_VAL 1e500 86 #define HUGE_VALF 1e50f 87 #define HUGE_VALL 1e500L 88 #define NAN __nan( ) 89 #define __MATH_H_ALWAYS_INLINE__ 90#endif 91 92#define INFINITY HUGE_VALF 93 94/****************************************************************************** 95* Taxonomy of floating point data types * 96******************************************************************************/ 97 98#define FP_NAN 1 99#define FP_INFINITE 2 100#define FP_ZERO 3 101#define FP_NORMAL 4 102#define FP_SUBNORMAL 5 103#define FP_SUPERNORMAL 6 104 105/* fma() *function call* is more costly than equivalent (in-line) multiply and add operations */ 106#undef FP_FAST_FMA 107#undef FP_FAST_FMAF 108#undef FP_FAST_FMAL 109 110/* The values returned by `ilogb' for 0 and NaN respectively. */ 111#define FP_ILOGB0 (-2147483647) 112#define FP_ILOGBNAN (2147483647) 113 114/* Bitmasks for the math_errhandling macro. */ 115#define MATH_ERRNO 1 /* errno set by math functions. */ 116#define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */ 117 118#define math_errhandling (__math_errhandling()) 119extern int __math_errhandling ( void ); 120 121/******************************************************************************** 122* * 123* Inquiry macros * 124* * 125* fpclassify Returns one of the FP_* values. * 126* isnormal Non-zero if and only if the argument x is normalized. * 127* isfinite Non-zero if and only if the argument x is finite. * 128* isnan Non-zero if and only if the argument x is a NaN. * 129* signbit Non-zero if and only if the sign of the argument x is * 130* negative. This includes, NaNs, infinities and zeros. * 131* * 132********************************************************************************/ 133 134#if (__WANT_LONG_DOUBLE_FORMAT__ - 0L == 128L) 135 #define fpclassify(x) \ 136 ( sizeof (x) == sizeof(float ) ? __fpclassifyf((float)x) \ 137 : sizeof (x) == sizeof(double) ? __fpclassifyd((double)x) \ 138 : __fpclassify ((long double)x)) 139 140 extern int __fpclassifyf(float ); 141 extern int __fpclassifyd(double ); 142 extern int __fpclassify (long double); 143 144 #if defined( __GNUC__ ) && ! defined( __XLC__ ) && 0 == __FINITE_MATH_ONLY__ 145 /* Yes, that's right. You only get the fast iswhatever() macros if you do NOT turn on -ffast-math. */ 146 /* These inline functions require the compiler to be compiling to standard in order to work. */ 147 /* -ffast-math, among other things, implies that NaNs don't happen. The compiler can in that case */ 148 /* optimize x != x to be false always, wheras it would be true for NaNs. That breaks __inline_isnan() */ 149 /* below. */ 150 151 #define isnormal(x) \ 152 ( sizeof (x) == sizeof(float ) ? __inline_isnormalf((float)(x)) \ 153 : sizeof (x) == sizeof(double) ? __inline_isnormald((double)(x)) \ 154 : __inline_isnormal ((long double)(x))) 155 156 #define isfinite(x) \ 157 ( sizeof (x) == sizeof(float ) ? __inline_isfinitef((float)(x)) \ 158 : sizeof (x) == sizeof(double) ? __inline_isfinited((double)(x)) \ 159 : __inline_isfinite ((long double)(x))) 160 161 #define isinf(x) \ 162 ( sizeof (x) == sizeof(float ) ? __inline_isinff((float)(x)) \ 163 : sizeof (x) == sizeof(double) ? __inline_isinfd((double)(x)) \ 164 : __inline_isinf ((long double)(x))) 165 166 #define isnan(x) \ 167 ( sizeof (x) == sizeof(float ) ? __inline_isnanf((float)(x)) \ 168 : sizeof (x) == sizeof(double) ? __inline_isnand((double)(x)) \ 169 : __inline_isnan ((long double)(x))) 170 171 #define signbit(x) \ 172 ( sizeof (x) == sizeof(float ) ? __inline_signbitf((float)(x)) \ 173 : sizeof (x) == sizeof(double) ? __inline_signbitd((double)(x)) \ 174 : __inline_signbit((long double)(x))) 175 176 /* Developers who are calling __isnan, __isnormal, __isinf, etc. and now encountering errors are calling private APIs */ 177 /* that are deprecated. Please use the official C99 sanctioned macros listed above instead. */ 178 179 static __inline__ int __inline_isfinitef (float ) __MATH_H_ALWAYS_INLINE__; 180 static __inline__ int __inline_isfinited (double ) __MATH_H_ALWAYS_INLINE__; 181 static __inline__ int __inline_isfinite (long double) __MATH_H_ALWAYS_INLINE__; 182 static __inline__ int __inline_isinff (float ) __MATH_H_ALWAYS_INLINE__; 183 static __inline__ int __inline_isinfd (double ) __MATH_H_ALWAYS_INLINE__; 184 static __inline__ int __inline_isinf (long double) __MATH_H_ALWAYS_INLINE__; 185 static __inline__ int __inline_isnanf (float ) __MATH_H_ALWAYS_INLINE__; 186 static __inline__ int __inline_isnand (double ) __MATH_H_ALWAYS_INLINE__; 187 static __inline__ int __inline_isnan (long double) __MATH_H_ALWAYS_INLINE__; 188 static __inline__ int __inline_isnormalf (float ) __MATH_H_ALWAYS_INLINE__; 189 static __inline__ int __inline_isnormald (double ) __MATH_H_ALWAYS_INLINE__; 190 static __inline__ int __inline_isnormal (long double) __MATH_H_ALWAYS_INLINE__; 191 static __inline__ int __inline_signbitf (float ) __MATH_H_ALWAYS_INLINE__; 192 static __inline__ int __inline_signbitd (double ) __MATH_H_ALWAYS_INLINE__; 193 static __inline__ int __inline_signbit (long double) __MATH_H_ALWAYS_INLINE__; 194 195 static __inline__ int __inline_isinff( float __x ) { return __builtin_fabsf(__x) == __builtin_inff(); } 196 static __inline__ int __inline_isinfd( double __x ) { return __builtin_fabs(__x) == __builtin_inf(); } 197 static __inline__ int __inline_isinf( long double __x ) { return __builtin_fabsl(__x) == __builtin_infl(); } 198 static __inline__ int __inline_isfinitef( float __x ) { return __x == __x && __builtin_fabsf(__x) != __builtin_inff(); } 199 static __inline__ int __inline_isfinited( double __x ) { return __x == __x && __builtin_fabs(__x) != __builtin_inf(); } 200 static __inline__ int __inline_isfinite( long double __x ) { return __x == __x && __builtin_fabsl(__x) != __builtin_infl(); } 201 static __inline__ int __inline_isnanf( float __x ) { return __x != __x; } 202 static __inline__ int __inline_isnand( double __x ) { return __x != __x; } 203 static __inline__ int __inline_isnan( long double __x ) { return __x != __x; } 204 static __inline__ int __inline_signbitf( float __x ) { union{ float __f; unsigned int __u; }__u; __u.__f = __x; return (int)(__u.__u >> 31); } 205 static __inline__ int __inline_signbitd( double __x ) { union{ double __f; unsigned long __u; }__u; __u.__f = __x; return (int)(__u.__u >> ( 8 * sizeof( __u.__u) - 1)); } 206 static __inline__ int __inline_signbit( long double __x ){ union{ long double __ld; unsigned long __p; }__u; __u.__ld = __x; return (int) (__u.__p >> ( 8 * sizeof( __u.__p) - 1)); } 207 static __inline__ int __inline_isnormalf( float __x ) { float fabsf = __builtin_fabsf(__x); if( __x != __x ) return 0; return fabsf < __builtin_inff() && fabsf >= __FLT_MIN__; } 208 static __inline__ int __inline_isnormald( double __x ) { double fabsf = __builtin_fabs(__x); if( __x != __x ) return 0; return fabsf < __builtin_inf() && fabsf >= __DBL_MIN__; } 209 static __inline__ int __inline_isnormal( long double __x ) { long double fabsf = __builtin_fabsl(__x); if( __x != __x ) return 0; return fabsf < __builtin_infl() && fabsf >= __LDBL_MIN__; } 210 211 #else 212 213 #define isnormal(x) \ 214 ( sizeof (x) == sizeof(float ) ? __isnormalf((float)(x)) \ 215 : sizeof (x) == sizeof(double) ? __isnormald((double)(x)) \ 216 : __isnormal ((long double)(x))) 217 218 #define isfinite(x) \ 219 ( sizeof (x) == sizeof(float ) ? __isfinitef((float)(x)) \ 220 : sizeof (x) == sizeof(double) ? __isfinited((double)(x)) \ 221 : __isfinite ((long double)(x))) 222 223 #define isinf(x) \ 224 ( sizeof (x) == sizeof(float ) ? __isinff((float)(x)) \ 225 : sizeof (x) == sizeof(double) ? __isinfd((double)(x)) \ 226 : __isinf ((long double)(x))) 227 228 #define isnan(x) \ 229 ( sizeof (x) == sizeof(float ) ? __isnanf((float)(x)) \ 230 : sizeof (x) == sizeof(double) ? __isnand((double)(x)) \ 231 : __isnan ((long double)(x))) 232 233 #define signbit(x) \ 234 ( sizeof (x) == sizeof(float ) ? __signbitf((float)(x)) \ 235 : sizeof (x) == sizeof(double) ? __signbitd((double)(x)) \ 236 : __signbitl((long double)(x))) 237 238 239 extern int __isnormalf (float ); 240 extern int __isnormald (double ); 241 extern int __isnormal (long double); 242 243 extern int __isfinitef (float ); 244 extern int __isfinited (double ); 245 extern int __isfinite (long double); 246 247 extern int __isinff (float ); 248 extern int __isinfd (double ); 249 extern int __isinf (long double); 250 251 extern int __isnanf (float ); 252 extern int __isnand (double ); 253 extern int __isnan (long double); 254 255 extern int __signbitf (float ); 256 extern int __signbitd (double ); 257 extern int __signbitl (long double); 258 259 #endif 260 261#else 262 #define fpclassify(x) \ 263 ( sizeof (x) == sizeof(float ) ? __fpclassifyf((float)(x)) : __fpclassifyd((double)(x)) ) 264 265 extern int __fpclassifyf(float ); 266 extern int __fpclassifyd(double ); 267 268 #if defined( __GNUC__ ) && ! defined( __XLC__ ) && 0 == __FINITE_MATH_ONLY__ 269 /* Yes, that's right. You only get the fast iswhatever() macros if you do NOT turn on -ffast-math. */ 270 /* These inline functions require the compiler to be compiling to standard in order to work. */ 271 /* -ffast-math, among other things, implies that NaNs don't happen. The compiler can in that case */ 272 /* optimize x != x to be false always, wheras it would be true for NaNs. That breaks __inline_isnan() */ 273 /* below. */ 274 #define isnormal(x) \ 275 ( sizeof (x) == sizeof(float ) ? __inline_isnormalf((float)(x)) : __inline_isnormald((double)(x)) ) 276 277 #define isfinite(x) \ 278 ( sizeof (x) == sizeof(float ) ? __inline_isfinitef((float)(x)) : __inline_isfinited((double)(x)) ) 279 280 #define isinf(x) \ 281 ( sizeof (x) == sizeof(float ) ? __inline_isinff((float)(x)) : __inline_isinfd((double)(x)) ) 282 283 #define isnan(x) \ 284 ( sizeof (x) == sizeof(float ) ? __inline_isnanf((float)(x)) : __inline_isnand((double)(x)) ) 285 286 #define signbit(x) \ 287 ( sizeof (x) == sizeof(float ) ? __inline_signbitf((float)(x)) : __inline_signbitd((double)(x)) ) 288 289 /* Developers who are calling __isnan, __isnormal, __isinf, etc. and now encountering errors are calling private APIs */ 290 /* that are deprecated. Please use the official C99 sanctioned macros listed above instead. */ 291 292 static __inline__ int __inline_isfinitef (float ) __MATH_H_ALWAYS_INLINE__; 293 static __inline__ int __inline_isfinited (double ) __MATH_H_ALWAYS_INLINE__; 294 static __inline__ int __inline_isfinite (long double) __MATH_H_ALWAYS_INLINE__; 295 static __inline__ int __inline_isinff (float ) __MATH_H_ALWAYS_INLINE__; 296 static __inline__ int __inline_isinfd (double ) __MATH_H_ALWAYS_INLINE__; 297 static __inline__ int __inline_isinf (long double) __MATH_H_ALWAYS_INLINE__; 298 static __inline__ int __inline_isnanf (float ) __MATH_H_ALWAYS_INLINE__; 299 static __inline__ int __inline_isnand (double ) __MATH_H_ALWAYS_INLINE__; 300 static __inline__ int __inline_isnan (long double) __MATH_H_ALWAYS_INLINE__; 301 static __inline__ int __inline_isnormalf (float ) __MATH_H_ALWAYS_INLINE__; 302 static __inline__ int __inline_isnormald (double ) __MATH_H_ALWAYS_INLINE__; 303 static __inline__ int __inline_isnormal (long double) __MATH_H_ALWAYS_INLINE__; 304 static __inline__ int __inline_signbitf (float ) __MATH_H_ALWAYS_INLINE__; 305 static __inline__ int __inline_signbitd (double ) __MATH_H_ALWAYS_INLINE__; 306 static __inline__ int __inline_signbit (long double) __MATH_H_ALWAYS_INLINE__; 307 308 static __inline__ int __inline_isinff( float __x ) { return __builtin_fabsf(__x) == __builtin_inff(); } 309 static __inline__ int __inline_isinfd( double __x ) { return __builtin_fabs(__x) == __builtin_inf(); } 310 static __inline__ int __inline_isinf( long double __x ) { return __builtin_fabsl(__x) == __builtin_infl(); } 311 static __inline__ int __inline_isfinitef( float __x ) { return __x == __x && __builtin_fabsf(__x) != __builtin_inff(); } 312 static __inline__ int __inline_isfinited( double __x ) { return __x == __x && __builtin_fabs(__x) != __builtin_inf(); } 313 static __inline__ int __inline_isfinite( long double __x ) { return __x == __x && __builtin_fabsl(__x) != __builtin_infl(); } 314 static __inline__ int __inline_isnanf( float __x ) { return __x != __x; } 315 static __inline__ int __inline_isnand( double __x ) { return __x != __x; } 316 static __inline__ int __inline_isnan( long double __x ) { return __x != __x; } 317 static __inline__ int __inline_signbitf( float __x ) { union{ float __f; unsigned int __u; }__u; __u.__f = __x; return (int)(__u.__u >> 31); } 318 static __inline__ int __inline_signbitd( double __x ) { union{ double __f; unsigned long __u; }__u; __u.__f = __x; return (int)(__u.__u >> ( 8 * sizeof( __u.__u) - 1)); } 319 static __inline__ int __inline_signbit( long double __x ){ union{ long double __ld; unsigned long __p; }__u; __u.__ld = __x; return (int) (__u.__p >> ( 8 * sizeof( __u.__p) - 1)); } 320 static __inline__ int __inline_isnormalf( float __x ) { float fabsf = __builtin_fabsf(__x); if( __x != __x ) return 0; return fabsf < __builtin_inff() && fabsf >= __FLT_MIN__; } 321 static __inline__ int __inline_isnormald( double __x ) { double fabsf = __builtin_fabs(__x); if( __x != __x ) return 0; return fabsf < __builtin_inf() && fabsf >= __DBL_MIN__; } 322 static __inline__ int __inline_isnormal( long double __x ) { long double fabsf = __builtin_fabsl(__x); if( __x != __x ) return 0; return fabsf < __builtin_infl() && fabsf >= __LDBL_MIN__; } 323 324 #else 325 326 #define isnormal(x) \ 327 ( sizeof (x) == sizeof(float ) ? __isnormalf((float)(x)) : __isnormald((double)(x)) ) 328 329 #define isfinite(x) \ 330 ( sizeof (x) == sizeof(float ) ? __isfinitef((float)(x)) : __isfinited((double)(x)) ) 331 332 #define isinf(x) \ 333 ( sizeof (x) == sizeof(float ) ? __isinff((float)(x)) : __isinfd((double)(x)) ) 334 335 #define isnan(x) \ 336 ( sizeof (x) == sizeof(float ) ? __isnanf((float)(x)) : __isnand((double)(x)) ) 337 338 #define signbit(x) \ 339 ( sizeof (x) == sizeof(float ) ? __signbitf((float)(x)) : __signbitd((double)(x)) ) 340 341 342 extern int __isnormalf (float ); 343 extern int __isnormald (double ); 344 345 extern int __isfinitef (float ); 346 extern int __isfinited (double ); 347 348 extern int __isinff (float ); 349 extern int __isinfd (double ); 350 351 extern int __isnanf (float ); 352 extern int __isnand (double ); 353 354 extern int __signbitf (float ); 355 extern int __signbitd (double ); 356 357 #endif 358 359#endif /* __WANT_LONG_DOUBLE_FORMAT__ */ 360 361 362/******************************************************************************** 363* * 364* Math Functions * 365* * 366********************************************************************************/ 367 368extern double acos( double ); 369extern float acosf( float ); 370 371extern double asin( double ); 372extern float asinf( float ); 373 374extern double atan( double ); 375extern float atanf( float ); 376 377extern double atan2( double, double ); 378extern float atan2f( float, float ); 379 380extern double cos( double ); 381extern float cosf( float ); 382 383extern double sin( double ); 384extern float sinf( float ); 385 386extern double tan( double ); 387extern float tanf( float ); 388 389extern double acosh( double ); 390extern float acoshf( float ); 391 392extern double asinh( double ); 393extern float asinhf( float ); 394 395extern double atanh( double ); 396extern float atanhf( float ); 397 398extern double cosh( double ); 399extern float coshf( float ); 400 401extern double sinh( double ); 402extern float sinhf( float ); 403 404extern double tanh( double ); 405extern float tanhf( float ); 406 407extern double exp( double ); 408extern float expf( float ); 409 410extern double exp2( double ); 411extern float exp2f( float ); 412 413extern double expm1( double ); 414extern float expm1f( float ); 415 416extern double log( double ); 417extern float logf( float ); 418 419extern double log10( double ); 420extern float log10f( float ); 421 422extern double log2( double ); 423extern float log2f( float ); 424 425extern double log1p( double ); 426extern float log1pf( float ); 427 428extern double logb( double ); 429extern float logbf( float ); 430 431extern double modf( double, double * ); 432extern float modff( float, float * ); 433 434extern double ldexp( double, int ); 435extern float ldexpf( float, int ); 436 437extern double frexp( double, int * ); 438extern float frexpf( float, int * ); 439 440extern int ilogb( double ); 441extern int ilogbf( float ); 442 443extern double scalbn( double, int ); 444extern float scalbnf( float, int ); 445 446extern double scalbln( double, long int ); 447extern float scalblnf( float, long int ); 448 449extern double fabs( double ); 450extern float fabsf( float ); 451 452extern double cbrt( double ); 453extern float cbrtf( float ); 454 455extern double hypot( double, double ); 456extern float hypotf( float, float ); 457 458extern double pow( double, double ); 459extern float powf( float, float ); 460 461extern double sqrt( double ); 462extern float sqrtf( float ); 463 464extern double erf( double ); 465extern float erff( float ); 466 467extern double erfc( double ); 468extern float erfcf( float ); 469 470extern double lgamma( double ); 471extern float lgammaf( float ); 472 473extern double tgamma( double ); 474extern float tgammaf( float ); 475 476extern double ceil( double ); 477extern float ceilf( float ); 478 479extern double floor( double ); 480extern float floorf( float ); 481 482extern double nearbyint( double ); 483extern float nearbyintf( float ); 484 485extern double rint( double ); 486extern float rintf( float ); 487 488extern long int lrint( double ); 489extern long int lrintf( float ); 490 491extern double round( double ); 492extern float roundf( float ); 493 494extern long int lround( double ); 495extern long int lroundf( float ); 496 497#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) 498 /* C90 doesn't know about long long. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. */ 499 extern long long int llrint( double ); 500 extern long long int llrintf( float ); 501 502 extern long long int llround( double ); 503 extern long long int llroundf( float ); 504#endif /*#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) */ 505 506extern double trunc( double ); 507extern float truncf( float ); 508 509extern double fmod( double, double ); 510extern float fmodf( float, float ); 511 512extern double remainder( double, double ); 513extern float remainderf( float, float ); 514 515extern double remquo( double, double, int * ); 516extern float remquof( float, float, int * ); 517 518extern double copysign( double, double ); 519extern float copysignf( float, float ); 520 521extern double nan( const char * ); 522extern float nanf( const char * ); 523 524extern double nextafter( double, double ); 525extern float nextafterf( float, float ); 526 527 528extern double fdim( double, double ); 529extern float fdimf( float, float ); 530 531extern double fmax( double, double ); 532extern float fmaxf( float, float ); 533 534extern double fmin( double, double ); 535extern float fminf( float, float ); 536 537extern double fma( double, double, double ); 538extern float fmaf( float, float, float ); 539 540#if ( __WANT_LONG_DOUBLE_FORMAT__ - 0L > 0L ) 541extern long double acosl( long double ) __LIBMLDBL_COMPAT(acosl); 542extern long double asinl( long double ) __LIBMLDBL_COMPAT(asinl); 543extern long double atanl( long double ) __LIBMLDBL_COMPAT(atanl); 544extern long double atan2l( long double, long double ) __LIBMLDBL_COMPAT(atan2l); 545extern long double cosl( long double ) __LIBMLDBL_COMPAT(cosl); 546extern long double sinl( long double ) __LIBMLDBL_COMPAT(sinl); 547extern long double tanl( long double ) __LIBMLDBL_COMPAT(tanl); 548extern long double acoshl( long double ) __LIBMLDBL_COMPAT(acoshl); 549extern long double asinhl( long double ) __LIBMLDBL_COMPAT(asinhl); 550extern long double atanhl( long double ) __LIBMLDBL_COMPAT(atanhl); 551extern long double coshl( long double ) __LIBMLDBL_COMPAT(coshl); 552extern long double sinhl( long double ) __LIBMLDBL_COMPAT(sinhl); 553extern long double tanhl( long double ) __LIBMLDBL_COMPAT(tanhl); 554extern long double expl( long double ) __LIBMLDBL_COMPAT(expl); 555extern long double exp2l( long double ) __LIBMLDBL_COMPAT(exp2l); 556extern long double expm1l( long double ) __LIBMLDBL_COMPAT(expm1l); 557extern long double logl( long double ) __LIBMLDBL_COMPAT(logl); 558extern long double log10l( long double ) __LIBMLDBL_COMPAT(log10l); 559extern long double log2l( long double ) __LIBMLDBL_COMPAT(log2l); 560extern long double log1pl( long double ) __LIBMLDBL_COMPAT(log1pl); 561extern long double logbl( long double ) __LIBMLDBL_COMPAT(logbl); 562extern long double modfl( long double, long double * ) __LIBMLDBL_COMPAT(modfl); 563extern long double ldexpl( long double, int ) __LIBMLDBL_COMPAT(ldexpl); 564extern long double frexpl( long double, int * ) __LIBMLDBL_COMPAT(frexpl); 565extern int ilogbl( long double ) __LIBMLDBL_COMPAT(ilogbl); 566extern long double scalbnl( long double, int ) __LIBMLDBL_COMPAT(scalbnl); 567extern long double scalblnl( long double, long int ) __LIBMLDBL_COMPAT(scalblnl); 568extern long double fabsl( long double ) __LIBMLDBL_COMPAT(fabsl); 569extern long double cbrtl( long double ) __LIBMLDBL_COMPAT(cbrtl); 570extern long double hypotl( long double, long double ) __LIBMLDBL_COMPAT(hypotl); 571extern long double powl( long double, long double ) __LIBMLDBL_COMPAT(powl); 572extern long double sqrtl( long double ) __LIBMLDBL_COMPAT(sqrtl); 573extern long double erfl( long double ) __LIBMLDBL_COMPAT(erfl); 574extern long double erfcl( long double ) __LIBMLDBL_COMPAT(erfcl); 575extern long double lgammal( long double ) __LIBMLDBL_COMPAT(lgammal); 576extern long double tgammal( long double ) __LIBMLDBL_COMPAT(tgammal); 577extern long double ceill( long double ) __LIBMLDBL_COMPAT(ceill); 578extern long double floorl( long double ) __LIBMLDBL_COMPAT(floorl); 579extern long double nearbyintl( long double ) __LIBMLDBL_COMPAT(nearbyintl); 580extern long double rintl( long double ) __LIBMLDBL_COMPAT(rintl); 581extern long int lrintl( long double ) __LIBMLDBL_COMPAT(lrintl); 582extern long double roundl( long double ) __LIBMLDBL_COMPAT(roundl); 583extern long int lroundl( long double ) __LIBMLDBL_COMPAT(lroundl); 584 585#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) 586 /* C90 doesn't know about long long. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. */ 587 extern long long int llrintl( long double ) __LIBMLDBL_COMPAT(llrintl); 588 extern long long int llroundl( long double ) __LIBMLDBL_COMPAT(llroundl); 589#endif /* #if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) */ 590 591extern long double truncl( long double ) __LIBMLDBL_COMPAT(truncl); 592extern long double fmodl( long double, long double) __LIBMLDBL_COMPAT(fmodl); 593extern long double remainderl( long double, long double ) __LIBMLDBL_COMPAT(remainderl); 594extern long double remquol( long double, long double, int * ) __LIBMLDBL_COMPAT(remquol); 595extern long double copysignl( long double, long double ) __LIBMLDBL_COMPAT(copysignl); 596extern long double nanl( const char * ) __LIBMLDBL_COMPAT(nanl); 597extern long double nextafterl( long double, long double ) __LIBMLDBL_COMPAT(nextafterl); 598extern double nexttoward( double, long double ) __LIBMLDBL_COMPAT(nexttoward); 599extern float nexttowardf( float, long double ) __LIBMLDBL_COMPAT(nexttowardf); 600extern long double nexttowardl( long double, long double ) __LIBMLDBL_COMPAT(nexttowardl); 601extern long double fdiml( long double, long double ) __LIBMLDBL_COMPAT(fdiml); 602extern long double fmaxl( long double, long double ) __LIBMLDBL_COMPAT(fmaxl); 603extern long double fminl( long double, long double ) __LIBMLDBL_COMPAT(fminl); 604extern long double fmal( long double, long double, long double ) __LIBMLDBL_COMPAT(fmal); 605#endif /* __WANT_LONG_DOUBLE_FORMAT__ */ 606 607#define isgreater(x, y) __builtin_isgreater ((x),(y)) 608#define isgreaterequal(x, y) __builtin_isgreaterequal ((x),(y)) 609#define isless(x, y) __builtin_isless ((x),(y)) 610#define islessequal(x, y) __builtin_islessequal ((x),(y)) 611#define islessgreater(x, y) __builtin_islessgreater ((x),(y)) 612#define isunordered(x, y) __builtin_isunordered ((x),(y)) 613 614extern double __inf( void ); 615extern float __inff( void ); 616extern float __nan( void ); /* 10.3 (and later) must retain in ABI for backward compatability */ 617 618#if !defined(_ANSI_SOURCE) 619extern double j0 ( double ); 620extern double j1 ( double ); 621extern double jn ( int, double ); 622 623extern double y0 ( double ); 624extern double y1 ( double ); 625extern double yn ( int, double ); 626 627/* 628 * Scalb Travellers' advisory: 629 * --------------------------- 630 * 631 * Reduction of Information advisory -- This advisory may constitute "too much information". Readers who are easily panicked 632 * or confused may be needlessly panicked or confused by this advisory. 633 * 634 * We are in the process of retiring the legacy scalb. IEEE-754 did not specify what the argument types should be 635 * for scalb. We guessed scalb(double, int) -- ints are faster to use here -- but our guess and what later standards 636 * standard eventually settled on did not agree. To be compliant with these standards, our scalb needs to be scalb(double, double). 637 * Unfortunately, we have a commitment to be binary compatible with old software compiled against scalb(double, int) 638 * for older operating systems, so the old symbol _scalb must live on in perpetuity in the __ppc__ binary interface to service 639 * this need. To deal with this problem, we have introduced a new binary symbol _scalb$UNIX2003 and did some magic below 640 * so that when you now compile against scalb() on a __ppc__ application, you get linked to _scalb$UNIX2003 instead. Thus, 641 * this constitutes a source level *** API CHANGE *** from scalb( double, int ) to scalb( double, double) on __ppc__ only 642 * that your source will need to contend with if you compile with this header. On __ppc__, all ints are exactly representable 643 * as doubles so from an arithmetic standpoint, this should cause no changes arithmetically from parameters of int type, but there 644 * remains the danger of triggering various compiler warnings that might balloon to more serious problems under -Werror. 645 * 646 * On __ppc64__, __i386__ and future archs, scalb has always been scalb( double, double) and will continue to be so. Thus, this change 647 * will make scalb on all platforms behave identically, with the same parameter types. The change will also eliminate GCC warnings about 648 * the math.h scalb declaration not matching the gcc4 builtin version. 649 * 650 * The intent is that you will "never know" that a change occurred, and your code should "just do the right thing" without modification. 651 * However, if you would like to sidestep any problems associated with this move, it is suggested that you use the C99 scalbn or scalbln 652 * or single/long double variants as appropriate instead. Their behavior and type is rigorously defined. There should be no hidden arithmetic 653 * "gotchas" if you simply replace all legacy calls to scalb with scalbn, since they essentially do the same thing. If you 654 * decide to take this step, you should exercise due diligence to make sure that scalbn is present in the oldest version of 655 * MacOS X that you support. Otherwise, your application may fail to load on older systems. C99 support was introduced in MacOS X.3.9. 656 * 657 * Use of the symbol _scalb$UNIX2003 should not in itself be construed to mean that scalb$UNIX2003 necessarily is UNIX 2003 compliant. 658 * UNIX is a registered trademark of The Open Group. 659 */ 660 661/* maps to _scalb$UNIX2003 on __ppc__ and _scalb elsewhere */ 662#if defined( __ppc__ ) 663 #if defined( __GNUC__ ) && ! defined( __XLC__ ) && ( ! defined( __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1040 ) 664 extern double scalb ( double, double ) __asm("_scalb$UNIX2003" ); 665 #else 666 extern double scalb ( double , int ); 667 #endif 668#else 669 extern double scalb ( double, double ); 670#endif 671 672#define M_E 2.71828182845904523536028747135266250 /* e */ 673#define M_LOG2E 1.44269504088896340735992468100189214 /* log_2(e) */ 674#define M_LOG10E 0.434294481903251827651128918916605082 /* log_10(e) */ 675#define M_LN2 0.693147180559945309417232121458176568 /* log_e(2) */ 676#define M_LN10 2.30258509299404568401799145468436421 /* log_e(10) */ 677#define M_PI 3.14159265358979323846264338327950288 /* pi */ 678#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ 679#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ 680#define M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ 681#define M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ 682#define M_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ 683#define M_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ 684#define M_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ 685 686#define MAXFLOAT ((float)3.40282346638528860e+38) 687extern int signgam; 688 689#endif /* !defined(_ANSI_SOURCE) */ 690 691#if !defined(__NOEXTENSIONS__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 692#define __WANT_EXTENSIONS__ 693#endif 694 695#ifdef __WANT_EXTENSIONS__ 696 697#define FP_SNAN FP_NAN 698#define FP_QNAN FP_NAN 699 700extern long int rinttol ( double ); 701 702extern long int roundtol ( double ); 703 704typedef struct __complex_s { 705 double Real; 706 double Imag; 707} __complex_t; 708 709/* 710 * XOPEN/SVID 711 */ 712#if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 713 714#if (!defined(_XOPEN_SOURCE) || defined(_DARWIN_C_SOURCE)) 715enum fdversion {_fdlibm_ieee = -1, _fdlibm_svid, _fdlibm_xopen, _fdlibm_posix}; /* Legacy fdlibm constructs */ 716#define fdlibm_ieee _fdlibm_ieee 717#define fdlibm_svid _fdlibm_svid 718#define fdlibm_xopen _fdlibm_xopen 719#define fdlibm_posix _fdlibm_posix 720 721#define _LIB_VERSION_TYPE enum fdversion 722#define _LIB_VERSION _fdlib_version 723 724/* if global variable _LIB_VERSION is not desirable, one may 725 * change the following to be a constant by: 726 * #define _LIB_VERSION_TYPE const enum version 727 * In that case, after one initializes the value _LIB_VERSION (see 728 * s_lib_version.c) during compile time, it cannot be modified 729 * in the middle of a program 730 */ 731extern _LIB_VERSION_TYPE _LIB_VERSION; 732 733#define _IEEE_ fdlibm_ieee 734#define _SVID_ fdlibm_svid 735#define _XOPEN_ fdlibm_xopen 736#define _POSIX_ fdlibm_posix 737 738#if !defined(__cplusplus) 739struct exception { 740 int type; 741 char *name; 742 double arg1; 743 double arg2; 744 double retval; 745}; 746#endif 747 748#define HUGE MAXFLOAT 749 750/* 751 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 752 * (one may replace the following line by "#include <values.h>") 753 */ 754 755#define X_TLOSS 1.41484755040568800000e+16 756 757#define DOMAIN 1 758#define SING 2 759#define OVERFLOW 3 760#define UNDERFLOW 4 761#define TLOSS 5 762#define PLOSS 6 763 764#endif /* (!_XOPEN_SOURCE || _DARWIN_C_SOURCE) */ 765#endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 766 767#if !defined( __STRICT_ANSI__) && !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 768 769extern int finite ( double ); 770 771extern double gamma ( double ); 772 773#if (!defined(_XOPEN_SOURCE) || defined(_DARWIN_C_SOURCE)) 774 775#if !defined(__cplusplus) 776extern int matherr ( struct exception * ); 777#endif 778 779/* 780 * IEEE Test Vector 781 */ 782extern double significand ( double ); 783 784/* 785 * BSD math library entry points 786 */ 787extern double drem ( double, double ); 788 789/* 790 * Reentrant version of gamma & lgamma; passes signgam back by reference 791 * as the second argument; user must allocate space for signgam. 792 */ 793#ifdef _REENTRANT 794extern double gamma_r ( double, int * ); 795extern double lgamma_r ( double, int * ); 796#endif /* _REENTRANT */ 797#endif /* (!_XOPEN_SOURCE || _DARWIN_C_SOURCE) */ 798#endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ 799 800#endif /* __WANT_EXTENSIONS__ */ 801 802/* 803 * The following replacements for libm's floor, floorf, ceil, and ceilf are activated 804 * when the flag "-ffast-math" is passed to the gcc compiler. These functions do not 805 * distinguish between -0.0 and 0.0, so are not IEC6509 compliant for argument -0.0. 806 */ 807#if defined(__FAST_MATH__) && !defined(__cplusplus) 808 809#define __FSELS(e,t,f) (((e) >= 0.0f) ? (t) : (f)) 810#define __FSEL(e,t,f) (((e) >= 0.0) ? (t) : (f)) 811 812static __inline__ float __fastmath_floorf( float f ) __attribute__((__always_inline__)); 813static __inline__ float __fastmath_floorf( float f ) 814{ 815 float b, c, d, e, g, h, t; 816 817 c = __FSELS( f, -8388608.f, 8388608.f ); b = fabsf( f ); 818 d = f - c; e = b - 8388608.f; 819 __asm__("" : "+f" (d)); /* Tell compiler value of d cannot be optimized away. */ 820 d = d + c; 821 g = f - d; 822 h = __FSELS( g, 0.0f, 1.0f ); 823 t = d - h; 824 return __FSELS( e, f, t ); 825} 826 827static __inline__ float __fastmath_ceilf( float f ) __attribute__((__always_inline__)); 828static __inline__ float __fastmath_ceilf( float f ) 829{ 830 float b, c, d, e, g, h, t; 831 832 c = __FSELS( f, -8388608.f, 8388608.f ); b = fabsf( f ); 833 d = f - c; e = b - 8388608.f; 834 __asm__("" : "+f" (d)); /* Tell compiler value of d cannot be optimized away. */ 835 d = d + c; 836 g = d - f; 837 h = __FSELS( g, 0.0f, 1.0f ); 838 t = d + h; 839 return __FSELS( e, f, t ); 840} 841 842static __inline__ double __fastmath_floor( double f ) __attribute__((__always_inline__)); 843static __inline__ double __fastmath_floor( double f ) 844{ 845 double b, c, d, e, g, h, t; 846 847 c = __FSEL( f, -4503599627370496., 4503599627370496. ); b = fabs( f ); 848 d = f - c; e = b - 4503599627370496.; 849 __asm__("" : "+f" (d)); /* Tell compiler value of d cannot be optimized away. */ 850 d = d + c; 851 g = f - d; 852 h = __FSEL( g, 0.0, 1.0 ); 853 t = d - h; 854 return __FSEL( e, f, t ); 855} 856 857static __inline__ double __fastmath_ceil( double f ) __attribute__((__always_inline__)); 858static __inline__ double __fastmath_ceil( double f ) 859{ 860 double b, c, d, e, g, h, t; 861 862 c = __FSEL( f, -4503599627370496., 4503599627370496. ); b = fabs( f ); 863 d = f - c; e = b - 4503599627370496.; 864 __asm__("" : "+f" (d)); /* Tell compiler value of d cannot be optimized away. */ 865 d = d + c; 866 g = d - f; 867 h = __FSEL( g, 0.0, 1.0 ); 868 t = d + h; 869 return __FSEL( e, f, t ); 870} 871 872#define floorf(x) __fastmath_floorf((x)) 873#define ceilf(x) __fastmath_ceilf((x)) 874#define floor(x) __fastmath_floor((x)) 875#define ceil(x) __fastmath_ceil((x)) 876 877#endif /* __FAST_MATH__ && !__cplusplus */ 878 879#ifdef __cplusplus 880} 881#endif 882 883#endif /* __MATH__ */