this repo has no description
at fixPythonPipStalling 525 lines 22 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#ifdef __cplusplus 34extern "C" { 35#endif 36 37/****************************************************************************** 38* Floating point data types * 39******************************************************************************/ 40 41/* Define float_t and double_t per C standard, ISO/IEC 9899:1999 7.12 2, 42 taking advantage of GCC's __FLT_EVAL_METHOD__ (which a compiler may 43 define anytime and GCC does) that shadows FLT_EVAL_METHOD (which a compiler 44 must and may define only in float.h). 45*/ 46#if __FLT_EVAL_METHOD__ == 0 47 typedef float float_t; 48 typedef double double_t; 49#elif __FLT_EVAL_METHOD__ == 1 50 typedef double float_t; 51 typedef double double_t; 52#elif __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ == -1 53 typedef long double float_t; 54 typedef long double double_t; 55#else /* __FLT_EVAL_METHOD__ */ 56 #error "Unsupported value of __FLT_EVAL_METHOD__." 57#endif /* __FLT_EVAL_METHOD__ */ 58 59 60#if defined(__GNUC__) 61 #define HUGE_VAL __builtin_huge_val() 62 #define HUGE_VALF __builtin_huge_valf() 63 #define HUGE_VALL __builtin_huge_vall() 64 #define NAN __builtin_nanf("0x7fc00000") /* Constant expression, can be used as initializer. */ 65 #define __MATH_H_ALWAYS_INLINE__ __attribute__ ((__always_inline__)) 66 67 #if defined( __LONG_DOUBLE_128__ ) 68 // This is the arm Libm header. Arm has 64-bit long doubles. 69 // If you are trying to build for Intel or PowerPC this is not the right header. 70 #error This math library does not support 128-bit long doubles 71 #endif 72#else 73 #define HUGE_VAL 1e500 74 #define HUGE_VALF 1e50f 75 #define HUGE_VALL 1e5000L 76 #define NAN __nan( ) 77 #define __MATH_H_ALWAYS_INLINE__ 78#endif 79 80#define INFINITY HUGE_VALF 81 82 83/****************************************************************************** 84* Taxonomy of floating point data types * 85******************************************************************************/ 86 87#define FP_NAN 1 88#define FP_INFINITE 2 89#define FP_ZERO 3 90#define FP_NORMAL 4 91#define FP_SUBNORMAL 5 92#define FP_SUPERNORMAL 6 /* meaningful only on PowerPC */ 93 94/* fma() *function call* is more costly than equivalent (in-line) multiply and add operations */ 95/* For single and double precision, the cost isn't too bad, because we can fall back on higher */ 96/* precision hardware, with the necessary range to handle infinite precision products. However, */ 97/* expect the long double fma to be at least an order of magnitude slower than a simple multiply */ 98/* and an add. */ 99#undef FP_FAST_FMA 100#undef FP_FAST_FMAF 101#undef FP_FAST_FMAL 102 103/* The values returned by `ilogb' for 0 and NaN respectively. */ 104#define FP_ILOGB0 (-2147483647 - 1) 105#define FP_ILOGBNAN (-2147483647 - 1) 106 107/* Bitmasks for the math_errhandling macro. */ 108#define MATH_ERRNO 1 /* errno set by math functions. */ 109#define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */ 110 111#define math_errhandling (__math_errhandling()) 112extern int __math_errhandling ( void ); 113 114/******************************************************************************** 115* * 116* Inquiry macros * 117* * 118* fpclassify Returns one of the FP_* values. * 119* isnormal Non-zero if and only if the argument x is normalized. * 120* isfinite Non-zero if and only if the argument x is finite. * 121* isnan Non-zero if and only if the argument x is a NaN. * 122* signbit Non-zero if and only if the sign of the argument x is * 123* negative. This includes, NaNs, infinities and zeros. * 124* * 125********************************************************************************/ 126 127#define fpclassify(x) \ 128 ( sizeof (x) == sizeof(float ) ? __fpclassifyf((float)(x)) \ 129 : sizeof (x) == sizeof(double) ? __fpclassify((double)(x)) \ 130 : __fpclassifyl ((long double)(x))) 131 132extern int __fpclassifyf(float ); 133extern int __fpclassify(double ); 134extern int __fpclassifyl(long double); 135 136 137/* 138 Note that these inline functions will fail to return expected results if you turn on unsafe math optimization flags, 139 including -ffast-math. This is not a bug. You have explicitly told the compiler that NaN's and Infs never happen. 140 As a result, the compiler simply assumes that they can't happen and things like isnan() return false even when 141 presented with a NaN. 142*/ 143#define isnormal(x) \ 144 ( sizeof (x) == sizeof(float ) ? __inline_isnormalf((float)(x)) \ 145 : sizeof (x) == sizeof(double) ? __inline_isnormald((double)(x)) \ 146 : __inline_isnormal ((long double)(x))) 147 148#define isfinite(x) \ 149 ( sizeof (x) == sizeof(float ) ? __inline_isfinitef((float)(x)) \ 150 : sizeof (x) == sizeof(double) ? __inline_isfinited((double)(x)) \ 151 : __inline_isfinite ((long double)(x))) 152 153#define isinf(x) \ 154 ( sizeof (x) == sizeof(float ) ? __inline_isinff((float)(x)) \ 155 : sizeof (x) == sizeof(double) ? __inline_isinfd((double)(x)) \ 156 : __inline_isinf ((long double)(x))) 157 158#define isnan(x) \ 159 ( sizeof (x) == sizeof(float ) ? __inline_isnanf((float)(x)) \ 160 : sizeof (x) == sizeof(double) ? __inline_isnand((double)(x)) \ 161 : __inline_isnan ((long double)(x))) 162 163#define signbit(x) \ 164 ( sizeof (x) == sizeof(float ) ? __inline_signbitf((float)(x)) \ 165 : sizeof (x) == sizeof(double) ? __inline_signbitd((double)(x)) \ 166 : __inline_signbit((long double)(x))) 167 168static __inline__ int __inline_isfinitef (float ) __MATH_H_ALWAYS_INLINE__; 169static __inline__ int __inline_isfinited (double ) __MATH_H_ALWAYS_INLINE__; 170static __inline__ int __inline_isfinite (long double) __MATH_H_ALWAYS_INLINE__; 171static __inline__ int __inline_isinff (float ) __MATH_H_ALWAYS_INLINE__; 172static __inline__ int __inline_isinfd (double ) __MATH_H_ALWAYS_INLINE__; 173static __inline__ int __inline_isinf (long double) __MATH_H_ALWAYS_INLINE__; 174static __inline__ int __inline_isnanf (float ) __MATH_H_ALWAYS_INLINE__; 175static __inline__ int __inline_isnand (double ) __MATH_H_ALWAYS_INLINE__; 176static __inline__ int __inline_isnan (long double) __MATH_H_ALWAYS_INLINE__; 177static __inline__ int __inline_isnormalf (float ) __MATH_H_ALWAYS_INLINE__; 178static __inline__ int __inline_isnormald (double ) __MATH_H_ALWAYS_INLINE__; 179static __inline__ int __inline_isnormal (long double) __MATH_H_ALWAYS_INLINE__; 180static __inline__ int __inline_signbitf (float ) __MATH_H_ALWAYS_INLINE__; 181static __inline__ int __inline_signbitd (double ) __MATH_H_ALWAYS_INLINE__; 182static __inline__ int __inline_signbit (long double) __MATH_H_ALWAYS_INLINE__; 183 184static __inline__ int __inline_isinff( float __x ) { return __builtin_fabsf(__x) == __builtin_inff(); } 185static __inline__ int __inline_isinfd( double __x ) { return __builtin_fabs(__x) == __builtin_inf(); } 186static __inline__ int __inline_isinf( long double __x ) { return __builtin_fabsl(__x) == __builtin_infl(); } 187static __inline__ int __inline_isfinitef( float __x ) { return __x == __x && __builtin_fabsf(__x) != __builtin_inff(); } 188static __inline__ int __inline_isfinited( double __x ) { return __x == __x && __builtin_fabs(__x) != __builtin_inf(); } 189static __inline__ int __inline_isfinite( long double __x ) { return __x == __x && __builtin_fabsl(__x) != __builtin_infl(); } 190static __inline__ int __inline_isnanf( float __x ) { return __x != __x; } 191static __inline__ int __inline_isnand( double __x ) { return __x != __x; } 192static __inline__ int __inline_isnan( long double __x ) { return __x != __x; } 193static __inline__ int __inline_signbitf( float __x ) { union{ float __f; unsigned int __u; }__u; __u.__f = __x; return (int)(__u.__u >> 31); } 194static __inline__ int __inline_signbitd( double __x ) { union{ double __f; unsigned long long __u; }__u; __u.__f = __x; return (int)(__u.__u >> 63); } 195static __inline__ int __inline_signbit( long double __x ){ union{ double __f; unsigned long long __u; }__u; __u.__f = __x; return (int)(__u.__u >> 63); } 196static __inline__ int __inline_isnormalf( float __x ) { float fabsf = __builtin_fabsf(__x); if( __x != __x ) return 0; return fabsf < __builtin_inff() && fabsf >= __FLT_MIN__; } 197static __inline__ int __inline_isnormald( double __x ) { double fabsf = __builtin_fabs(__x); if( __x != __x ) return 0; return fabsf < __builtin_inf() && fabsf >= __DBL_MIN__; } 198static __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__; } 199 200 201 202/******************************************************************************** 203* * 204* Math Functions * 205* * 206********************************************************************************/ 207 208extern double acos( double ); 209extern float acosf( float ); 210 211extern double asin( double ); 212extern float asinf( float ); 213 214extern double atan( double ); 215extern float atanf( float ); 216 217extern double atan2( double, double ); 218extern float atan2f( float, float ); 219 220extern double cos( double ); 221extern float cosf( float ); 222 223extern double sin( double ); 224extern float sinf( float ); 225 226extern double tan( double ); 227extern float tanf( float ); 228 229extern double acosh( double ); 230extern float acoshf( float ); 231 232extern double asinh( double ); 233extern float asinhf( float ); 234 235extern double atanh( double ); 236extern float atanhf( float ); 237 238extern double cosh( double ); 239extern float coshf( float ); 240 241extern double sinh( double ); 242extern float sinhf( float ); 243 244extern double tanh( double ); 245extern float tanhf( float ); 246 247extern double exp ( double ); 248extern float expf ( float ); 249 250extern double exp2 ( double ); 251extern float exp2f ( float ); 252 253extern double expm1 ( double ); 254extern float expm1f ( float ); 255 256extern double log ( double ); 257extern float logf ( float ); 258 259extern double log10 ( double ); 260extern float log10f ( float ); 261 262extern double log2 ( double ); 263extern float log2f ( float ); 264 265extern double log1p ( double ); 266extern float log1pf ( float ); 267 268extern double logb ( double ); 269extern float logbf ( float ); 270 271extern double modf ( double, double * ); 272extern float modff ( float, float * ); 273 274extern double ldexp ( double, int ); 275extern float ldexpf ( float, int ); 276 277extern double frexp ( double, int * ); 278extern float frexpf ( float, int * ); 279 280extern int ilogb ( double ); 281extern int ilogbf ( float ); 282 283extern double scalbn ( double, int ); 284extern float scalbnf ( float, int ); 285 286extern double scalbln ( double, long int ); 287extern float scalblnf ( float, long int ); 288 289extern double fabs( double ); 290extern float fabsf( float ); 291 292extern double cbrt( double ); 293extern float cbrtf( float ); 294 295extern double hypot ( double, double ); 296extern float hypotf ( float, float ); 297 298extern double pow ( double, double ); 299extern float powf ( float, float ); 300 301extern double sqrt( double ); 302extern float sqrtf( float ); 303 304extern double erf( double ); 305extern float erff( float ); 306 307extern double erfc( double ); 308extern float erfcf( float ); 309 310/* lgamma and lgammaf are not thread-safe. The thread-safe variants lgamma_r and lgammaf_r 311 are available if _REENTRANT symbol is defined 312 */ 313extern double lgamma( double ); 314extern float lgammaf( float ); 315 316extern double tgamma( double ); 317extern float tgammaf( float ); 318 319extern double ceil ( double ); 320extern float ceilf ( float ); 321 322extern double floor ( double ); 323extern float floorf ( float ); 324 325extern double nearbyint ( double ); 326extern float nearbyintf ( float ); 327 328extern double rint ( double ); 329extern float rintf ( float ); 330 331extern long int lrint ( double ); 332extern long int lrintf ( float ); 333 334extern double round ( double ); 335extern float roundf ( float ); 336 337extern long int lround ( double ); 338extern long int lroundf ( float ); 339 340#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) 341 342 /* long long is not part of C90. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. */ 343 extern long long int llrint ( double ); 344 extern long long int llrintf ( float ); 345 346 extern long long int llround ( double ); 347 extern long long int llroundf ( float ); 348 349#endif /* #if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) */ 350 351extern double trunc ( double ); 352extern float truncf ( float ); 353 354extern double fmod ( double, double ); 355extern float fmodf ( float, float ); 356 357extern double remainder ( double, double ); 358extern float remainderf ( float, float ); 359 360extern double remquo ( double, double, int * ); 361extern float remquof ( float, float, int * ); 362 363extern double copysign ( double, double ); 364extern float copysignf ( float, float ); 365 366extern double nan( const char * ); 367extern float nanf( const char * ); 368 369extern double nextafter ( double, double ); 370extern float nextafterf ( float, float ); 371 372extern double fdim ( double, double ); 373extern float fdimf ( float, float ); 374 375extern double fmax ( double, double ); 376extern float fmaxf ( float, float ); 377 378extern double fmin ( double, double ); 379extern float fminf ( float, float ); 380 381extern double fma ( double, double, double ); 382extern float fmaf ( float, float, float ); 383 384extern long double acosl(long double); 385extern long double asinl(long double); 386extern long double atanl(long double); 387extern long double atan2l(long double, long double); 388extern long double cosl(long double); 389extern long double sinl(long double); 390extern long double tanl(long double); 391extern long double acoshl(long double); 392extern long double asinhl(long double); 393extern long double atanhl(long double); 394extern long double coshl(long double); 395extern long double sinhl(long double); 396extern long double tanhl(long double); 397extern long double expl(long double); 398extern long double exp2l(long double); 399extern long double expm1l(long double); 400extern long double logl(long double); 401extern long double log10l(long double); 402extern long double log2l(long double); 403extern long double log1pl(long double); 404extern long double logbl(long double); 405extern long double modfl(long double, long double *); 406extern long double ldexpl(long double, int); 407extern long double frexpl(long double, int *); 408extern int ilogbl(long double); 409extern long double scalbnl(long double, int); 410extern long double scalblnl(long double, long int); 411extern long double fabsl(long double); 412extern long double cbrtl(long double); 413extern long double hypotl(long double, long double); 414extern long double powl(long double, long double); 415extern long double sqrtl(long double); 416extern long double erfl(long double); 417extern long double erfcl(long double); 418/* lgammal is not thread-safe. The thread-safe variant lgammal_r is available if _REENTRANT symbol is defined */ 419extern long double lgammal(long double); 420extern long double tgammal(long double); 421extern long double ceill(long double); 422extern long double floorl(long double); 423extern long double nearbyintl(long double); 424extern long double rintl(long double); 425extern long int lrintl(long double); 426extern long double roundl(long double); 427extern long int lroundl(long double); 428 429#if ( defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L ) || ! defined( __STRICT_ANSI__ ) || ! defined( __GNUC__ ) 430 // long long is not part of C90. Make sure you are passing -std=c99 or -std=gnu99 or better if you need this. 431 extern long long int llrintl(long double); 432 extern long long int llroundl(long double); 433#endif 434 435extern long double truncl(long double); 436extern long double fmodl(long double, long double); 437extern long double remainderl(long double, long double); 438extern long double remquol(long double, long double, int *); 439extern long double copysignl(long double, long double); 440extern long double nanl(const char *); 441extern long double nextafterl(long double, long double); 442extern double nexttoward(double, long double); 443extern float nexttowardf(float, long double); 444extern long double nexttowardl(long double, long double); 445extern long double fdiml(long double, long double); 446extern long double fmaxl(long double, long double); 447extern long double fminl(long double, long double); 448extern long double fmal(long double, long double, long double); 449 450#define isgreater(x, y) __builtin_isgreater ((x),(y)) 451#define isgreaterequal(x, y) __builtin_isgreaterequal ((x),(y)) 452#define isless(x, y) __builtin_isless ((x),(y)) 453#define islessequal(x, y) __builtin_islessequal ((x),(y)) 454#define islessgreater(x, y) __builtin_islessgreater ((x),(y)) 455#define isunordered(x, y) __builtin_isunordered ((x),(y)) 456 457 458#if !defined(_ANSI_SOURCE) 459 460/* 461 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 462 * (one may replace the following line by "#include <values.h>") 463 */ 464 465#define X_TLOSS 1.41484755040568800000e+16 466 467/* The bessel functions are available in iPhone OS 3.2 and later. */ 468#include <Availability.h> 469 470extern double j0 ( double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 471extern double j1 ( double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 472extern double jn ( int, double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 473extern double y0 ( double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 474extern double y1 ( double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 475extern double yn ( int, double ) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 476 477extern double scalb ( double, double ); 478extern int signgam; /* required for unix 2003 */ 479 480/* 481 * Constants required by UNIX 2003 / POSIX: 482 * 483 * http://www.opengroup.org/onlinepubs/007908799/xsh/math.h.html 484 * 485 * Even though these would be more useful as long double, POSIX requires these to be double. 486 */ 487#define M_E 2.71828182845904523536028747135266250 /* e */ 488#define M_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ 489#define M_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ 490#define M_LN2 0.693147180559945309417232121458176568 /* loge(2) */ 491#define M_LN10 2.30258509299404568401799145468436421 /* loge(10) */ 492#define M_PI 3.14159265358979323846264338327950288 /* pi */ 493#define M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ 494#define M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ 495#define M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ 496#define M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ 497#define M_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ 498#define M_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ 499#define M_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ 500 501#define MAXFLOAT 0x1.fffffep+127f 502 503 504#endif /* !defined(_ANSI_SOURCE) */ 505 506 507 508#if !defined(__NOEXTENSIONS__) && !defined(__STRICT_ANSI__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 509#ifdef _REENTRANT 510 511 /* Thread safe variants of the lgamma[fl]_r functions. */ 512 513extern float lgammaf_r(float, int *); 514extern double lgamma_r(double, int *); 515extern long double lgammal_r(long double, int *); 516#endif // _REENTRANT 517#endif // !defined(__NOEXTENSIONS__) && !defined(__STRICT_ANSI__) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 518 519 520 521#ifdef __cplusplus 522} 523#endif 524 525#endif /* __MATH__ */