File: /usr/include/math.h

Green shading in the line number column means the source is part of the translation unit, red means it is conditionally excluded. Highlighted line numbers link to the translation unit page. Highlighted macros link to the macro page.

       1: /*
       2:  * Copyright (c) 2002-2015 Apple 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: #ifndef __MATH_H__
      24: #define __MATH_H__
      25: 
      26: #ifndef __MATH__
      27: #define __MATH__
      28: #endif
      29: 
      30: #include <sys/cdefs.h>
      31: #include <Availability.h>
      32: 
      33: __BEGIN_DECLS
      34: 
      35: /******************************************************************************
      36:  * Floating point data types                                                  *
      37:  ******************************************************************************/
      38: 
      39: /*  Define float_t and double_t per C standard, ISO/IEC 9899:2011 7.12 2,
      40:     taking advantage of GCC's __FLT_EVAL_METHOD__ (which a compiler may
      41:     define anytime and GCC does) that shadows FLT_EVAL_METHOD (which a
      42:     compiler must define only in float.h).                                    */
      43: #if __FLT_EVAL_METHOD__ == 0
      44:     typedef float float_t;
      45:     typedef double double_t;
      46: #elif __FLT_EVAL_METHOD__ == 1
      47:     typedef double float_t;
      48:     typedef double double_t;
      49: #elif __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ == -1
      50:     typedef long double float_t;
      51:     typedef long double double_t;
      52: #else /* __FLT_EVAL_METHOD__ */
      53: #   error "Unsupported value of __FLT_EVAL_METHOD__."
      54: #endif /* __FLT_EVAL_METHOD__ */
      55: 
      56: #if defined(__GNUC__)
      57: #   define    HUGE_VAL     __builtin_huge_val()
      58: #   define    HUGE_VALF    __builtin_huge_valf()
      59: #   define    HUGE_VALL    __builtin_huge_vall()
      60: #   define    NAN          __builtin_nanf("0x7fc00000")
      61: #else
      62: #   define    HUGE_VAL     1e500
      63: #   define    HUGE_VALF    1e50f
      64: #   define    HUGE_VALL    1e5000L
      65: #   define    NAN          __nan()
      66: #endif
      67: 
      68: #define INFINITY    HUGE_VALF
      69: 
      70: /******************************************************************************
      71:  *      Taxonomy of floating point data types                                 *
      72:  ******************************************************************************/
      73: 
      74: #define FP_NAN          1
      75: #define FP_INFINITE     2
      76: #define FP_ZERO         3
      77: #define FP_NORMAL       4
      78: #define FP_SUBNORMAL    5
      79: #define FP_SUPERNORMAL  6 /* legacy PowerPC support; this is otherwise unused */
      80: 
      81: #if defined __arm64__ || defined __ARM_VFPV4__
      82: /*  On these architectures, fma(), fmaf( ), and fmal( ) are generally about as
      83:     fast as (or faster than) separate multiply and add of the same operands.  */
      84: #   define FP_FAST_FMA     1
      85: #   define FP_FAST_FMAF    1
      86: #   define FP_FAST_FMAL    1
      87: #elif (defined __i386__ || defined __x86_64__) && defined __FMA__
      88: /*  When targeting the FMA ISA extension, fma() and fmaf( ) are generally
      89:     about as fast as (or faster than) separate multiply and add of the same
      90:     operands, but fmal( ) may be more costly.                                 */
      91: #   define FP_FAST_FMA     1
      92: #   define FP_FAST_FMAF    1
      93: #   undef  FP_FAST_FMAL
      94: #else
      95: /*  On these architectures, fma( ), fmaf( ), and fmal( ) function calls are
      96:     significantly more costly than separate multiply and add operations.      */
      97: #   undef  FP_FAST_FMA
      98: #   undef  FP_FAST_FMAF
      99: #   undef  FP_FAST_FMAL
     100: #endif
     101: 
     102: /* The values returned by `ilogb' for 0 and NaN respectively. */
     103: #define FP_ILOGB0      (-2147483647 - 1)
     104: #define FP_ILOGBNAN    (-2147483647 - 1)
     105: 
     106: /* Bitmasks for the math_errhandling macro.  */
     107: #define MATH_ERRNO        1    /* errno set by math functions.  */
     108: #define MATH_ERREXCEPT    2    /* Exceptions raised by math functions.  */
     109: 
     110: #define math_errhandling (__math_errhandling())
     111: extern int __math_errhandling(void);
     112: 
     113: /******************************************************************************
     114:  *                                                                            *
     115:  *                              Inquiry macros                                *
     116:  *                                                                            *
     117:  *  fpclassify      Returns one of the FP_* values.                           *
     118:  *  isnormal        Non-zero if and only if the argument x is normalized.     *
     119:  *  isfinite        Non-zero if and only if the argument x is finite.         *
     120:  *  isnan           Non-zero if and only if the argument x is a NaN.          *
     121:  *  signbit         Non-zero if and only if the sign of the argument x is     *
     122:  *                  negative.  This includes, NaNs, infinities and zeros.     *
     123:  *                                                                            *
     124:  ******************************************************************************/
     125: 
     126: #if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 1080) || \
     127:     (defined __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 60000)
     128: #   if defined __i386__ || defined __x86_64__
     129: #       define __fpclassifyl __fpclassify
     130: #       define __isnormall   __isnormal
     131: #       define __isfinitel   __isfinite
     132: #       define __isinfl      __isinf
     133: #       define __isnanl      __isnan
     134: #   elif defined __arm__
     135: #       define __fpclassifyd __fpclassify
     136: #   endif
     137: #endif
     138: 
     139: #define fpclassify(x)                                                    \
     140:     ( sizeof(x) == sizeof(float)  ? __fpclassifyf((float)(x))            \
     141:     : sizeof(x) == sizeof(double) ? __fpclassifyd((double)(x))           \
     142:                                   : __fpclassifyl((long double)(x)))
     143: 
     144: extern int __fpclassifyf(float);
     145: extern int __fpclassifyd(double);
     146: extern int __fpclassifyl(long double);
     147: 
     148: #if (defined(__GNUC__) && 0 == __FINITE_MATH_ONLY__) || \
     149:     (defined __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 60000 && defined __arm__)
     150: /*  These inline functions may fail to return expected results if unsafe
     151:     math optimizations like those enabled by -ffast-math are turned on.
     152:     Thus, (somewhat surprisingly) you only get the fast inline
     153:     implementations if such compiler options are NOT enabled.  This is
     154:     because the inline functions require the compiler to be adhering to
     155:     the standard in order to work properly; -ffast-math, among other
     156:     things, implies that NaNs don't happen, which allows the compiler to
     157:     optimize away checks like x != x, which might lead to things like
     158:     isnan(NaN) returning false.                                               
     159:  
     160:     Thus, if you compile with -ffast-math, actual function calls are
     161:     generated for these utilities.                                            */
     162:     
     163: #define isnormal(x)                                                      \
     164:     ( sizeof(x) == sizeof(float)  ? __inline_isnormalf((float)(x))       \
     165:     : sizeof(x) == sizeof(double) ? __inline_isnormald((double)(x))      \
     166:                                   : __inline_isnormall((long double)(x)))
     167: 
     168: #define isfinite(x)                                                      \
     169:     ( sizeof(x) == sizeof(float)  ? __inline_isfinitef((float)(x))       \
     170:     : sizeof(x) == sizeof(double) ? __inline_isfinited((double)(x))      \
     171:                                   : __inline_isfinitel((long double)(x)))
     172: 
     173: #define isinf(x)                                                         \
     174:     ( sizeof(x) == sizeof(float)  ? __inline_isinff((float)(x))          \
     175:     : sizeof(x) == sizeof(double) ? __inline_isinfd((double)(x))         \
     176:                                   : __inline_isinfl((long double)(x)))
     177: 
     178: #define isnan(x)                                                         \
     179:     ( sizeof(x) == sizeof(float)  ? __inline_isnanf((float)(x))          \
     180:     : sizeof(x) == sizeof(double) ? __inline_isnand((double)(x))         \
     181:                                   : __inline_isnanl((long double)(x)))
     182: 
     183: #define signbit(x)                                                       \
     184:     ( sizeof(x) == sizeof(float)  ? __inline_signbitf((float)(x))        \
     185:     : sizeof(x) == sizeof(double) ? __inline_signbitd((double)(x))       \
     186:                                   : __inline_signbitl((long double)(x)))
     187: 
     188: __header_always_inline int __inline_isfinitef(float);
     189: __header_always_inline int __inline_isfinited(double);
     190: __header_always_inline int __inline_isfinitel(long double);
     191: __header_always_inline int __inline_isinff(float);
     192: __header_always_inline int __inline_isinfd(double);
     193: __header_always_inline int __inline_isinfl(long double);
     194: __header_always_inline int __inline_isnanf(float);
     195: __header_always_inline int __inline_isnand(double);
     196: __header_always_inline int __inline_isnanl(long double);
     197: __header_always_inline int __inline_isnormalf(float);
     198: __header_always_inline int __inline_isnormald(double);
     199: __header_always_inline int __inline_isnormall(long double);
     200: __header_always_inline int __inline_signbitf(float);
     201: __header_always_inline int __inline_signbitd(double);
     202: __header_always_inline int __inline_signbitl(long double);
     203:     
     204: __header_always_inline int __inline_isfinitef(float __x) {
     205:     return __x == __x && __builtin_fabsf(__x) != __builtin_inff();
     206: }
     207: __header_always_inline int __inline_isfinited(double __x) {
     208:     return __x == __x && __builtin_fabs(__x) != __builtin_inf();
     209: }
     210: __header_always_inline int __inline_isfinitel(long double __x) {
     211:     return __x == __x && __builtin_fabsl(__x) != __builtin_infl();
     212: }
     213: __header_always_inline int __inline_isinff(float __x) {
     214:     return __builtin_fabsf(__x) == __builtin_inff();
     215: }
     216: __header_always_inline int __inline_isinfd(double __x) {
     217:     return __builtin_fabs(__x) == __builtin_inf();
     218: }
     219: __header_always_inline int __inline_isinfl(long double __x) {
     220:     return __builtin_fabsl(__x) == __builtin_infl();
     221: }
     222: __header_always_inline int __inline_isnanf(float __x) {
     223:     return __x != __x;
     224: }
     225: __header_always_inline int __inline_isnand(double __x) {
     226:     return __x != __x;
     227: }
     228: __header_always_inline int __inline_isnanl(long double __x) {
     229:     return __x != __x;
     230: }
     231: __header_always_inline int __inline_signbitf(float __x) {
     232:     union { float __f; unsigned int __u; } __u;
     233:     __u.__f = __x;
     234:     return (int)(__u.__u >> 31);
     235: }
     236: __header_always_inline int __inline_signbitd(double __x) {
     237:     union { double __f; unsigned long long __u; } __u;
     238:     __u.__f = __x;
     239:     return (int)(__u.__u >> 63);
     240: }
     241: #if defined __i386__ || defined __x86_64__
     242: __header_always_inline int __inline_signbitl(long double __x) {
     243:     union {
     244:         long double __ld;
     245:         struct{ unsigned long long __m; unsigned short __sexp; } __p;
     246:     } __u;
     247:     __u.__ld = __x;
     248:     return (int)(__u.__p.__sexp >> 15);
     249: }
     250: #else
     251: __header_always_inline int __inline_signbitl(long double __x) {
     252:     union { long double __f; unsigned long long __u;} __u;
     253:     __u.__f = __x;
     254:     return (int)(__u.__u >> 63);
     255: }
     256: #endif
     257: __header_always_inline int __inline_isnormalf(float __x) {
     258:     return __inline_isfinitef(__x) && __builtin_fabsf(__x) >= __FLT_MIN__;
     259: }
     260: __header_always_inline int __inline_isnormald(double __x) {
     261:     return __inline_isfinited(__x) && __builtin_fabs(__x) >= __DBL_MIN__;
     262: }
     263: __header_always_inline int __inline_isnormall(long double __x) {
     264:     return __inline_isfinitel(__x) && __builtin_fabsl(__x) >= __LDBL_MIN__;
     265: }
     266:     
     267: #else /* defined(__GNUC__) && 0 == __FINITE_MATH_ONLY__ */
     268: 
     269: /*  Implementations making function calls to fall back on when -ffast-math
     270:     or similar is specified.  These are not available in iOS versions prior
     271:     to 6.0.  If you need them, you must target that version or later.         */
     272:     
     273: #define isnormal(x)                                               \
     274:     ( sizeof(x) == sizeof(float)  ? __isnormalf((float)(x))       \
     275:     : sizeof(x) == sizeof(double) ? __isnormald((double)(x))      \
     276:                                   : __isnormall((long double)(x)))
     277:     
     278: #define isfinite(x)                                               \
     279:     ( sizeof(x) == sizeof(float)  ? __isfinitef((float)(x))       \
     280:     : sizeof(x) == sizeof(double) ? __isfinited((double)(x))      \
     281:                                   : __isfinitel((long double)(x)))
     282:     
     283: #define isinf(x)                                                  \
     284:     ( sizeof(x) == sizeof(float)  ? __isinff((float)(x))          \
     285:     : sizeof(x) == sizeof(double) ? __isinfd((double)(x))         \
     286:                                   : __isinfl((long double)(x)))
     287:     
     288: #define isnan(x)                                                  \
     289:     ( sizeof(x) == sizeof(float)  ? __isnanf((float)(x))          \
     290:     : sizeof(x) == sizeof(double) ? __isnand((double)(x))         \
     291:                                   : __isnanl((long double)(x)))
     292:     
     293: #define signbit(x)                                                \
     294:     ( sizeof(x) == sizeof(float)  ? __signbitf((float)(x))        \
     295:     : sizeof(x) == sizeof(double) ? __signbitd((double)(x))       \
     296:                                   : __signbitl((long double)(x)))
     297:     
     298: extern int __isnormalf(float);
     299: extern int __isnormald(double);
     300: extern int __isnormall(long double);
     301: extern int __isfinitef(float);
     302: extern int __isfinited(double);
     303: extern int __isfinitel(long double);
     304: extern int __isinff(float);
     305: extern int __isinfd(double);
     306: extern int __isinfl(long double);
     307: extern int __isnanf(float);
     308: extern int __isnand(double);
     309: extern int __isnanl(long double);
     310: extern int __signbitf(float);
     311: extern int __signbitd(double);
     312: extern int __signbitl(long double);
     313: 
     314: #endif /* defined(__GNUC__) && 0 == __FINITE_MATH_ONLY__ */
     315: 
     316: /******************************************************************************
     317:  *                                                                            *
     318:  *                              Math Functions                                *
     319:  *                                                                            *
     320:  ******************************************************************************/
     321:     
     322: extern float acosf(float);
     323: extern double acos(double);
     324: extern long double acosl(long double);
     325:     
     326: extern float asinf(float);
     327: extern double asin(double);
     328: extern long double asinl(long double);
     329:     
     330: extern float atanf(float);
     331: extern double atan(double);
     332: extern long double atanl(long double);
     333:     
     334: extern float atan2f(float, float);
     335: extern double atan2(double, double);
     336: extern long double atan2l(long double, long double);
     337:     
     338: extern float cosf(float);
     339: extern double cos(double);
     340: extern long double cosl(long double);
     341:     
     342: extern float sinf(float);
     343: extern double sin(double);
     344: extern long double sinl(long double);
     345:     
     346: extern float tanf(float);
     347: extern double tan(double);
     348: extern long double tanl(long double);
     349:     
     350: extern float acoshf(float);
     351: extern double acosh(double);
     352: extern long double acoshl(long double);
     353:     
     354: extern float asinhf(float);
     355: extern double asinh(double);
     356: extern long double asinhl(long double);
     357:     
     358: extern float atanhf(float);
     359: extern double atanh(double);
     360: extern long double atanhl(long double);
     361:     
     362: extern float coshf(float);
     363: extern double cosh(double);
     364: extern long double coshl(long double);
     365:     
     366: extern float sinhf(float);
     367: extern double sinh(double);
     368: extern long double sinhl(long double);
     369:     
     370: extern float tanhf(float);
     371: extern double tanh(double);
     372: extern long double tanhl(long double);
     373:     
     374: extern float expf(float);
     375: extern double exp(double);
     376: extern long double expl(long double);
     377: 
     378: extern float exp2f(float);
     379: extern double exp2(double); 
     380: extern long double exp2l(long double); 
     381: 
     382: extern float expm1f(float);
     383: extern double expm1(double); 
     384: extern long double expm1l(long double); 
     385: 
     386: extern float logf(float);
     387: extern double log(double);
     388: extern long double logl(long double);
     389: 
     390: extern float log10f(float);
     391: extern double log10(double);
     392: extern long double log10l(long double);
     393: 
     394: extern float log2f(float);
     395: extern double log2(double);
     396: extern long double log2l(long double);
     397: 
     398: extern float log1pf(float);
     399: extern double log1p(double);
     400: extern long double log1pl(long double);
     401: 
     402: extern float logbf(float);
     403: extern double logb(double);
     404: extern long double logbl(long double);
     405: 
     406: extern float modff(float, float *);
     407: extern double modf(double, double *);
     408: extern long double modfl(long double, long double *);
     409: 
     410: extern float ldexpf(float, int);
     411: extern double ldexp(double, int);
     412: extern long double ldexpl(long double, int);
     413: 
     414: extern float frexpf(float, int *);
     415: extern double frexp(double, int *);
     416: extern long double frexpl(long double, int *);
     417: 
     418: extern int ilogbf(float);
     419: extern int ilogb(double);
     420: extern int ilogbl(long double);
     421: 
     422: extern float scalbnf(float, int);
     423: extern double scalbn(double, int);
     424: extern long double scalbnl(long double, int);
     425: 
     426: extern float scalblnf(float, long int);
     427: extern double scalbln(double, long int);
     428: extern long double scalblnl(long double, long int);
     429: 
     430: extern float fabsf(float);
     431: extern double fabs(double);
     432: extern long double fabsl(long double);
     433: 
     434: extern float cbrtf(float);
     435: extern double cbrt(double);
     436: extern long double cbrtl(long double);
     437: 
     438: extern float hypotf(float, float);
     439: extern double hypot(double, double);
     440: extern long double hypotl(long double, long double);
     441: 
     442: extern float powf(float, float);
     443: extern double pow(double, double);
     444: extern long double powl(long double, long double);
     445: 
     446: extern float sqrtf(float);
     447: extern double sqrt(double);
     448: extern long double sqrtl(long double);
     449: 
     450: extern float erff(float);
     451: extern double erf(double);
     452: extern long double erfl(long double);
     453: 
     454: extern float erfcf(float);
     455: extern double erfc(double);
     456: extern long double erfcl(long double);
     457: 
     458: /*    lgammaf, lgamma, and lgammal are not thread-safe. The thread-safe
     459:     variants lgammaf_r, lgamma_r, and lgammal_r are made available if
     460:     you define the _REENTRANT symbol before including <math.h>                */
     461: extern float lgammaf(float);
     462: extern double lgamma(double);
     463: extern long double lgammal(long double);
     464: 
     465: extern float tgammaf(float);
     466: extern double tgamma(double);
     467: extern long double tgammal(long double);
     468: 
     469: extern float ceilf(float);
     470: extern double ceil(double);
     471: extern long double ceill(long double);
     472: 
     473: extern float floorf(float);
     474: extern double floor(double);
     475: extern long double floorl(long double);
     476: 
     477: extern float nearbyintf(float);
     478: extern double nearbyint(double);
     479: extern long double nearbyintl(long double);
     480: 
     481: extern float rintf(float);
     482: extern double rint(double);
     483: extern long double rintl(long double);
     484: 
     485: extern long int lrintf(float);
     486: extern long int lrint(double);
     487: extern long int lrintl(long double);
     488: 
     489: extern float roundf(float);
     490: extern double round(double);
     491: extern long double roundl(long double);
     492: 
     493: extern long int lroundf(float);
     494: extern long int lround(double);
     495: extern long int lroundl(long double);
     496:     
     497: /*  long long is not part of C90. Make sure you are passing -std=c99 or
     498:     -std=gnu99 or higher if you need these functions returning long longs     */
     499: #if !(__DARWIN_NO_LONG_LONG)
     500: extern long long int llrintf(float);
     501: extern long long int llrint(double);
     502: extern long long int llrintl(long double);
     503: 
     504: extern long long int llroundf(float);
     505: extern long long int llround(double);
     506: extern long long int llroundl(long double);
     507: #endif /* !(__DARWIN_NO_LONG_LONG) */
     508: 
     509: extern float truncf(float);
     510: extern double trunc(double);
     511: extern long double truncl(long double);
     512: 
     513: extern float fmodf(float, float);
     514: extern double fmod(double, double);
     515: extern long double fmodl(long double, long double);
     516: 
     517: extern float remainderf(float, float);
     518: extern double remainder(double, double);
     519: extern long double remainderl(long double, long double);
     520: 
     521: extern float remquof(float, float, int *);
     522: extern double remquo(double, double, int *);
     523: extern long double remquol(long double, long double, int *);
     524: 
     525: extern float copysignf(float, float);
     526: extern double copysign(double, double);
     527: extern long double copysignl(long double, long double);
     528: 
     529: extern float nanf(const char *);
     530: extern double nan(const char *);
     531: extern long double nanl(const char *);
     532: 
     533: extern float nextafterf(float, float);
     534: extern double nextafter(double, double);
     535: extern long double nextafterl(long double, long double);
     536: 
     537: extern double nexttoward(double, long double);
     538: extern float nexttowardf(float, long double);
     539: extern long double nexttowardl(long double, long double);
     540: 
     541: extern float fdimf(float, float);
     542: extern double fdim(double, double);
     543: extern long double fdiml(long double, long double);
     544: 
     545: extern float fmaxf(float, float);
     546: extern double fmax(double, double);
     547: extern long double fmaxl(long double, long double);
     548: 
     549: extern float fminf(float, float);
     550: extern double fmin(double, double);
     551: extern long double fminl(long double, long double);
     552: 
     553: extern float fmaf(float, float, float);
     554: extern double fma(double, double, double);
     555: extern long double fmal(long double, long double, long double);
     556: 
     557: #define isgreater(x, y) __builtin_isgreater((x),(y))
     558: #define isgreaterequal(x, y) __builtin_isgreaterequal((x),(y))
     559: #define isless(x, y) __builtin_isless((x),(y))
     560: #define islessequal(x, y) __builtin_islessequal((x),(y))
     561: #define islessgreater(x, y) __builtin_islessgreater((x),(y))
     562: #define isunordered(x, y) __builtin_isunordered((x),(y))
     563: 
     564: /* Legacy BSD API: please use C99 INFINITY macro instead.                     */
     565: extern float __inff(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     566: extern double __inf(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     567: extern long double __infl(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     568: /* Implementation detail; please use the standard C NAN macro instead.        */
     569: extern float __nan(void) __OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_NA);
     570: 
     571: /******************************************************************************
     572:  *  Reentrant variants of lgamma[fl]                                          *
     573:  ******************************************************************************/
     574: 
     575: #ifdef _REENTRANT
     576: /*  Reentrant variants of the lgamma[fl] functions.                           */
     577: extern float lgammaf_r(float, int *) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);
     578: extern double lgamma_r(double, int *) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);
     579: extern long double lgammal_r(long double, int *) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_1);
     580: #endif /* _REENTRANT */
     581: 
     582: /******************************************************************************
     583:  *  Apple extensions to the C standard                                        *
     584:  ******************************************************************************/
     585: 
     586: /*  Because these functions are not specified by any relevant standard, they
     587:     are prefixed with __, which places them in the implementor's namespace, so
     588:     they should not conflict with any developer or third-party code.  If they
     589:     are added to a relevant standard in the future, un-prefixed names may be
     590:     added to the library and they may be moved out of this section of the
     591:     header.                                                                   
     592:  
     593:     Because these functions are non-standard, they may not be available on non-
     594:     Apple platforms.                                                          */
     595: 
     596: /*  __exp10(x) returns 10**x.  Edge cases match those of exp( ) and exp2( ).  */
     597: extern float __exp10f(float) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     598: extern double __exp10(double) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     599: 
     600: /*  __sincos(x,sinp,cosp) computes the sine and cosine of x with a single
     601:     function call, storing the sine in the memory pointed to by sinp, and
     602:     the cosine in the memory pointed to by cosp. Edge cases match those of
     603:     separate calls to sin( ) and cos( ).                                      */
     604: __header_always_inline void __sincosf(float __x, float *__sinp, float *__cosp);
     605: __header_always_inline void __sincos(double __x, double *__sinp, double *__cosp);
     606: 
     607: /*  __sinpi(x) returns the sine of pi times x; __cospi(x) and __tanpi(x) return
     608:     the cosine and tangent, respectively.  These functions can produce a more
     609:     accurate answer than expressions of the form sin(M_PI * x) because they
     610:     avoid any loss of precision that results from rounding the result of the
     611:     multiplication M_PI * x.  They may also be significantly more efficient in
     612:     some cases because the argument reduction for these functions is easier
     613:     to compute.  Consult the man pages for edge case details.                 */
     614: extern float __cospif(float) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     615: extern double __cospi(double) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     616: extern float __sinpif(float) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     617: extern double __sinpi(double) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     618: extern float __tanpif(float) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     619: extern double __tanpi(double) __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
     620: 
     621: #if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090) || \
     622:     (defined __IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < 70000)
     623: /*  __sincos and __sincosf were introduced in OSX 10.9 and iOS 7.0.  When
     624:     targeting an older system, we simply split them up into discrete calls
     625:     to sin( ) and cos( ).                                                     */
     626: __header_always_inline void __sincosf(float __x, float *__sinp, float *__cosp) {
     627:   *__sinp = sinf(__x);
     628:   *__cosp = cosf(__x);
     629: }
     630: 
     631: __header_always_inline void __sincos(double __x, double *__sinp, double *__cosp) {
     632:   *__sinp = sin(__x);
     633:   *__cosp = cos(__x);
     634: }
     635: #else
     636: /*  __sincospi(x,sinp,cosp) computes the sine and cosine of pi times x with a
     637:     single function call, storing the sine in the memory pointed to by sinp,
     638:     and the cosine in the memory pointed to by cosp.  Edge cases match those
     639:     of separate calls to __sinpi( ) and __cospi( ), and are documented in the
     640:     man pages.
     641:  
     642:     These functions were introduced in OSX 10.9 and iOS 7.0.  Because they are
     643:     implemented as header inlines, weak-linking does not function as normal,
     644:     and they are simply hidden when targeting earlier OS versions.            */
     645: __header_always_inline void __sincospif(float __x, float *__sinp, float *__cosp);
     646: __header_always_inline void __sincospi(double __x, double *__sinp, double *__cosp);
     647: 
     648: /*  Implementation details of __sincos and __sincospi allowing them to return
     649:     two results while allowing the compiler to optimize away unnecessary load-
     650:     store traffic.  Although these interfaces are exposed in the math.h header
     651:     to allow compilers to generate better code, users should call __sincos[f]
     652:     and __sincospi[f] instead and allow the compiler to emit these calls.     */
     653: struct __float2 { float __sinval; float __cosval; };
     654: struct __double2 { double __sinval; double __cosval; };
     655: 
     656: extern struct __float2 __sincosf_stret(float);
     657: extern struct __double2 __sincos_stret(double);
     658: extern struct __float2 __sincospif_stret(float);
     659: extern struct __double2 __sincospi_stret(double);
     660: 
     661: __header_always_inline void __sincosf(float __x, float *__sinp, float *__cosp) {
     662:     const struct __float2 __stret = __sincosf_stret(__x);
     663:     *__sinp = __stret.__sinval; *__cosp = __stret.__cosval;
     664: }
     665: 
     666: __header_always_inline void __sincos(double __x, double *__sinp, double *__cosp) {
     667:     const struct __double2 __stret = __sincos_stret(__x);
     668:     *__sinp = __stret.__sinval; *__cosp = __stret.__cosval;
     669: }
     670: 
     671: __header_always_inline void __sincospif(float __x, float *__sinp, float *__cosp) {
     672:     const struct __float2 __stret = __sincospif_stret(__x);
     673:     *__sinp = __stret.__sinval; *__cosp = __stret.__cosval;
     674: }
     675: 
     676: __header_always_inline void __sincospi(double __x, double *__sinp, double *__cosp) {
     677:     const struct __double2 __stret = __sincospi_stret(__x);
     678:     *__sinp = __stret.__sinval; *__cosp = __stret.__cosval;
     679: }
     680: #endif
     681: 
     682: /******************************************************************************
     683:  *  POSIX/UNIX extensions to the C standard                                   *
     684:  ******************************************************************************/
     685: 
     686: #if __DARWIN_C_LEVEL >= 199506L
     687: extern double j0(double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     688: extern double j1(double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     689: extern double jn(int, double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     690: extern double y0(double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     691: extern double y1(double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     692: extern double yn(int, double) __OSX_AVAILABLE_STARTING(__MAC_10_0,__IPHONE_3_2); 
     693: extern double scalb(double, double); 
     694: extern int signgam;
     695: 
     696: /*  Even though these might be more useful as long doubles, POSIX requires
     697:     that they be double-precision literals.                                   */
     698: #define M_E         2.71828182845904523536028747135266250   /* e              */
     699: #define M_LOG2E     1.44269504088896340735992468100189214   /* log2(e)        */
     700: #define M_LOG10E    0.434294481903251827651128918916605082  /* log10(e)       */
     701: #define M_LN2       0.693147180559945309417232121458176568  /* loge(2)        */
     702: #define M_LN10      2.30258509299404568401799145468436421   /* loge(10)       */
     703: #define M_PI        3.14159265358979323846264338327950288   /* pi             */
     704: #define M_PI_2      1.57079632679489661923132169163975144   /* pi/2           */
     705: #define M_PI_4      0.785398163397448309615660845819875721  /* pi/4           */
     706: #define M_1_PI      0.318309886183790671537767526745028724  /* 1/pi           */
     707: #define M_2_PI      0.636619772367581343075535053490057448  /* 2/pi           */
     708: #define M_2_SQRTPI  1.12837916709551257389615890312154517   /* 2/sqrt(pi)     */
     709: #define M_SQRT2     1.41421356237309504880168872420969808   /* sqrt(2)        */
     710: #define M_SQRT1_2   0.707106781186547524400844362104849039  /* 1/sqrt(2)      */
     711: 
     712: #define MAXFLOAT    0x1.fffffep+127f
     713: #endif /* __DARWIN_C_LEVEL >= 199506L */
     714: 
     715: /*  Long-double versions of M_E, etc for convenience on Intel where long-
     716:     double is not the same as double.  Define __MATH_LONG_DOUBLE_CONSTANTS
     717:     to make these constants available.                                        */
     718: #if defined __MATH_LONG_DOUBLE_CONSTANTS
     719: #define M_El        0xa.df85458a2bb4a9bp-2L
     720: #define M_LOG2El    0xb.8aa3b295c17f0bcp-3L
     721: #define M_LOG10El   0xd.e5bd8a937287195p-5L
     722: #define M_LN2l      0xb.17217f7d1cf79acp-4L
     723: #define M_LN10l     0x9.35d8dddaaa8ac17p-2L
     724: #define M_PIl       0xc.90fdaa22168c235p-2L
     725: #define M_PI_2l     0xc.90fdaa22168c235p-3L
     726: #define M_PI_4l     0xc.90fdaa22168c235p-4L
     727: #define M_1_PIl     0xa.2f9836e4e44152ap-5L
     728: #define M_2_PIl     0xa.2f9836e4e44152ap-4L
     729: #define M_2_SQRTPIl 0x9.06eba8214db688dp-3L
     730: #define M_SQRT2l    0xb.504f333f9de6484p-3L
     731: #define M_SQRT1_2l  0xb.504f333f9de6484p-4L
     732: #endif /* defined __MATH_LONG_DOUBLE_CONSTANTS */
     733: 
     734: /******************************************************************************
     735:  *  Legacy BSD extensions to the C standard                                   *
     736:  ******************************************************************************/
     737: 
     738: #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
     739: #define FP_SNAN        FP_NAN
     740: #define FP_QNAN        FP_NAN
     741: #define    HUGE        MAXFLOAT
     742: #define X_TLOSS        1.41484755040568800000e+16 
     743: #define    DOMAIN        1
     744: #define    SING        2
     745: #define    OVERFLOW    3
     746: #define    UNDERFLOW    4
     747: #define    TLOSS        5
     748: #define    PLOSS        6
     749: 
     750: /* Legacy BSD API: please use C99 lrint( ) instead.                           */
     751: extern long int rinttol(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     752: /* Legacy BSD API: please use C99 lround( ) instead.                          */
     753: extern long int roundtol(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     754: /* Legacy BSD API: please use C99 remainder( ) instead.                       */
     755: extern double drem(double, double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     756: /* Legacy BSD API: please use C99 isfinite( ) instead.                        */
     757: extern int finite(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     758: /* Legacy BSD API: please use C99 tgamma( ) instead.                          */
     759: extern double gamma(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     760: /* Legacy BSD API: please use C99 frexp( ) instead.                           */
     761: extern double significand(double) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     762: 
     763: #if !defined __cplusplus
     764: struct exception {
     765:     int type;
     766:     char *name;
     767:     double arg1;
     768:     double arg2;
     769:     double retval;
     770: };
     771: /* Legacy API: does not do anything useful.                                   */
     772: extern int matherr(struct exception *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
     773: #endif /* !defined __cplusplus */
     774: #endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */
     775: 
     776: __END_DECLS
     777: #endif /* __MATH_H__ */
     778: