Home | History | Annotate | Download | only in include
      1 /*
      2  * ====================================================
      3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      4  *
      5  * Developed at SunPro, a Sun Microsystems, Inc. business.
      6  * Permission to use, copy, modify, and distribute this
      7  * software is freely granted, provided that this notice
      8  * is preserved.
      9  * ====================================================
     10  */
     11 
     12 /*
     13  * from: @(#)fdlibm.h 5.1 93/09/24
     14  * $FreeBSD$
     15  */
     16 
     17 #ifndef _MATH_H_
     18 #define _MATH_H_
     19 
     20 #include <sys/cdefs.h>
     21 #include <limits.h>
     22 
     23 __BEGIN_DECLS
     24 
     25 /* C11. */
     26 
     27 typedef double __double_t;
     28 typedef __double_t double_t;
     29 typedef float __float_t;
     30 typedef __float_t float_t;
     31 
     32 #define HUGE_VAL __builtin_huge_val()
     33 #define HUGE_VALF __builtin_huge_valf()
     34 #define HUGE_VALL __builtin_huge_vall()
     35 
     36 #define INFINITY __builtin_inff()
     37 
     38 #define NAN __builtin_nanf("")
     39 
     40 #define FP_INFINITE 0x01
     41 #define FP_NAN 0x02
     42 #define FP_NORMAL 0x04
     43 #define FP_SUBNORMAL 0x08
     44 #define FP_ZERO 0x10
     45 
     46 #if defined(__FP_FAST_FMA)
     47 #define FP_FAST_FMA 1
     48 #endif
     49 #if defined(__FP_FAST_FMAF)
     50 #define FP_FAST_FMAF 1
     51 #endif
     52 #if defined(__FP_FAST_FMAL)
     53 #define FP_FAST_FMAL 1
     54 #endif
     55 
     56 #define FP_ILOGB0 (-INT_MAX)
     57 #define FP_ILOGBNAN INT_MAX
     58 
     59 #define MATH_ERRNO 1
     60 #define MATH_ERREXCEPT 2
     61 #define math_errhandling MATH_ERREXCEPT
     62 
     63 #define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
     64 
     65 #define isfinite(x) __builtin_isfinite(x)
     66 
     67 #define isinf(x) __builtin_isinf(x)
     68 
     69 #define isnan(x) __builtin_isnan(x)
     70 
     71 #define isnormal(x) __builtin_isnormal(x)
     72 
     73 #define signbit(x) \
     74     ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
     75     : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
     76     : __builtin_signbitl(x))
     77 
     78 double acos(double __x);
     79 float acosf(float __x);
     80 long double acosl(long double __x) __RENAME_LDBL(acos, 3, 21);
     81 
     82 double asin(double __x);
     83 float asinf(float __x);
     84 long double asinl(long double __x) __RENAME_LDBL(asin, 3, 21);
     85 
     86 double atan(double __x);
     87 float atanf(float __x);
     88 long double atanl(long double __x) __RENAME_LDBL(atan, 3, 21);
     89 
     90 double atan2(double __y, double __x);
     91 float atan2f(float __y, float __x);
     92 long double atan2l(long double __y, long double __x) __RENAME_LDBL(atan2, 3, 21);
     93 
     94 double cos(double __x);
     95 float cosf(float __x);
     96 long double cosl(long double __x) __RENAME_LDBL(cos, 3, 21);
     97 
     98 double sin(double __x);
     99 float sinf(float __x);
    100 long double sinl(long double __x) __RENAME_LDBL(sin, 3, 21);
    101 
    102 double tan(double __x);
    103 float tanf(float __x);
    104 long double tanl(long double __x) __RENAME_LDBL(tan, 3, 21);
    105 
    106 double acosh(double __x);
    107 float acoshf(float __x);
    108 long double acoshl(long double __x) __RENAME_LDBL(acosh, 3, 21);
    109 
    110 double asinh(double __x);
    111 float asinhf(float __x);
    112 long double asinhl(long double __x) __RENAME_LDBL(asinh, 3, 21);
    113 
    114 double atanh(double __x);
    115 float atanhf(float __x);
    116 long double atanhl(long double __x) __RENAME_LDBL(atanh, 3, 21);
    117 
    118 double cosh(double __x);
    119 float coshf(float __x);
    120 long double coshl(long double __x) __RENAME_LDBL(cosh, 3, 21);
    121 
    122 double sinh(double __x);
    123 float sinhf(float __x);
    124 long double sinhl(long double __x) __RENAME_LDBL(sinh, 3, 21);
    125 
    126 double tanh(double __x);
    127 float tanhf(float __x);
    128 long double tanhl(long double __x) __RENAME_LDBL(tanh, 3, 21);
    129 
    130 double exp(double __x);
    131 float expf(float __x);
    132 long double expl(long double __x) __RENAME_LDBL(exp, 3, 21);
    133 
    134 double exp2(double __x);
    135 float exp2f(float __x);
    136 long double exp2l(long double __x) __RENAME_LDBL(exp2, 3, 21);
    137 
    138 double expm1(double __x);
    139 float expm1f(float __x);
    140 long double expm1l(long double __x) __RENAME_LDBL(expm1, 3, 21);
    141 
    142 double frexp(double __x, int* __exponent);
    143 float frexpf(float __x, int* __exponent);
    144 long double frexpl(long double __x, int* __exponent) __RENAME_LDBL(frexp, 3, 21);
    145 
    146 int ilogb(double __x) __attribute_const__;
    147 int ilogbf(float __x) __attribute_const__;
    148 int ilogbl(long double __x) __RENAME_LDBL(ilogb, 3, 3) __attribute_const__;
    149 
    150 double ldexp(double __x, int __exponent);
    151 float ldexpf(float __x, int __exponent);
    152 long double ldexpl(long double __x, int __exponent) __RENAME_LDBL(ldexp, 3, 3);
    153 
    154 double log(double __x);
    155 float logf(float __x);
    156 long double logl(long double __x) __RENAME_LDBL(log, 3, 21);
    157 
    158 double log10(double __x);
    159 float log10f(float __x);
    160 long double log10l(long double __x) __RENAME_LDBL(log10, 3, 21);
    161 
    162 double log1p(double __x);
    163 float log1pf(float __x);
    164 long double log1pl(long double __x) __RENAME_LDBL(log1p, 3, 21);
    165 
    166 double log2(double __x) __INTRODUCED_IN(18);
    167 float log2f(float __x) __INTRODUCED_IN(18);
    168 long double log2l(long double __x) __RENAME_LDBL(log2, 18, 18);
    169 
    170 double logb(double __x);
    171 float logbf(float __x);
    172 long double logbl(long double __x) __RENAME_LDBL(logb, 3, 18);
    173 
    174 double modf(double __x, double* __integral_part);
    175 float modff(float __x, float* __integral_part);
    176 long double modfl(long double __x, long double* __integral_part) __RENAME_LDBL(modf, 3, 21);
    177 
    178 double scalbn(double __x, int __exponent);
    179 float scalbnf(float __x, int __exponent);
    180 long double scalbnl(long double __x, int __exponent) __RENAME_LDBL(scalbn, 3, 3);
    181 
    182 /* TODO: once the NDK only supports >= 18, use __RENAME_LDBL here too. */
    183 double scalbln(double __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    184 float scalblnf(float __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    185 long double scalblnl(long double __x, long __exponent) __INTRODUCED_IN_X86(18) __VERSIONER_NO_GUARD;
    186 
    187 double cbrt(double __x);
    188 float cbrtf(float __x);
    189 long double cbrtl(long double __x) __RENAME_LDBL(cbrt, 3, 21);
    190 
    191 double fabs(double __x) __attribute_const__;
    192 float fabsf(float __x) __attribute_const__;
    193 long double fabsl(long double __x) __RENAME_LDBL(fabs, 3, 3) __attribute_const__;
    194 
    195 double hypot(double __x, double __y);
    196 float hypotf(float __x, float __y);
    197 long double hypotl(long double __x, long double __y) __RENAME_LDBL(hypot, 3, 21);
    198 
    199 double pow(double __x, double __y);
    200 float powf(float __x, float __y);
    201 long double powl(long double __x, long double __y) __RENAME_LDBL(pow, 3, 21);
    202 
    203 double sqrt(double __x);
    204 float sqrtf(float __x);
    205 long double sqrtl(long double __x) __RENAME_LDBL(sqrt, 3, 21);
    206 
    207 double erf(double __x);
    208 float erff(float __x);
    209 long double erfl(long double __x) __RENAME_LDBL(erf, 3, 21);
    210 
    211 double erfc(double __x);
    212 float erfcf(float __x);
    213 long double erfcl(long double __x) __RENAME_LDBL(erfc, 3, 21);
    214 
    215 double lgamma(double __x);
    216 float lgammaf(float __x);
    217 long double lgammal(long double __x) __RENAME_LDBL(lgamma, 3, 21);
    218 
    219 double tgamma(double __x);
    220 float tgammaf(float __x) __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
    221 long double tgammal(long double __x) __RENAME_LDBL(tgamma, 3, 21);
    222 
    223 double ceil(double __x);
    224 float ceilf(float __x);
    225 long double ceill(long double __x) __RENAME_LDBL(ceil, 3, 3);
    226 
    227 double floor(double __x);
    228 float floorf(float __x);
    229 long double floorl(long double __x) __RENAME_LDBL(floor, 3, 3);
    230 
    231 double nearbyint(double __x);
    232 float nearbyintf(float __x);
    233 long double nearbyintl(long double __x) __RENAME_LDBL(nearbyint, 3, 21);
    234 
    235 double rint(double __x);
    236 float rintf(float __x);
    237 long double rintl(long double __x) __RENAME_LDBL(rint, 3, 21);
    238 
    239 long lrint(double __x);
    240 long lrintf(float __x);
    241 long lrintl(long double __x) __RENAME_LDBL(lrint, 3, 21);
    242 
    243 long long llrint(double __x);
    244 long long llrintf(float __x);
    245 long long llrintl(long double __x) __RENAME_LDBL(llrint, 3, 21);
    246 
    247 double round(double __x);
    248 float roundf(float __x);
    249 long double roundl(long double __x) __RENAME_LDBL(roundl, 3, 3);
    250 
    251 long lround(double __x);
    252 long lroundf(float __x);
    253 long lroundl(long double __x) __RENAME_LDBL(lround, 3, 3);
    254 
    255 long long llround(double __x);
    256 long long llroundf(float __x);
    257 long long llroundl(long double __x) __RENAME_LDBL(llround, 3, 3);
    258 
    259 double trunc(double __x);
    260 float truncf(float __x);
    261 long double truncl(long double __x) __RENAME_LDBL(trunc, 3, 3);
    262 
    263 double fmod(double __x, double __y);
    264 float fmodf(float __x, float __y);
    265 long double fmodl(long double __x, long double __y) __RENAME_LDBL(fmod, 3, 21);
    266 
    267 double remainder(double __x, double __y);
    268 float remainderf(float __x, float __y);
    269 long double remainderl(long double __x, long double __y) __RENAME_LDBL(remainder, 3, 21);
    270 
    271 double remquo(double __x, double __y, int* __quotient_bits);
    272 float remquof(float __x, float __y, int* __quotient_bits);
    273 long double remquol(long double __x, long double __y, int* __quotient_bits) __RENAME_LDBL(remquo, 3, 21);
    274 
    275 double copysign(double __value, double __sign) __attribute_const__;
    276 float copysignf(float __value, float __sign) __attribute_const__;
    277 long double copysignl(long double __value, long double __sign) __RENAME_LDBL(copysign, 3, 3) __attribute_const__;
    278 
    279 double nan(const char* __kind) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
    280 float nanf(const char* __kind) __attribute_const__ __INTRODUCED_IN_ARM(13) __INTRODUCED_IN_MIPS(13) __INTRODUCED_IN_X86(9);
    281 long double nanl(const char* __kind) __RENAME_LDBL(nan, 13, 13) __attribute_const__;
    282 
    283 double nextafter(double __x, double __y);
    284 float nextafterf(float __x, float __y);
    285 long double nextafterl(long double __x, long double __y) __RENAME_LDBL(nextafter, 3, 21) __VERSIONER_NO_GUARD;
    286 
    287 double nexttoward(double __x, long double __y) __INTRODUCED_IN(18) __VERSIONER_NO_GUARD;
    288 float nexttowardf(float __x, long double __y);
    289 long double nexttowardl(long double __x, long double __y) __RENAME_LDBL(nexttoward, 18, 18) __VERSIONER_NO_GUARD;
    290 
    291 double fdim(double __x, double __y);
    292 float fdimf(float __x, float __y);
    293 long double fdiml(long double __x, long double __y) __RENAME_LDBL(fdim, 3, 3);
    294 
    295 double fmax(double __x, double __y) __attribute_const__;
    296 float fmaxf(float __x, float __y) __attribute_const__;
    297 long double fmaxl(long double __x, long double __y) __RENAME_LDBL(fmax, 3, 3) __attribute_const__;
    298 
    299 double fmin(double __x, double __y) __attribute_const__;
    300 float fminf(float __x, float __y) __attribute_const__;
    301 long double fminl(long double __x, long double __y) __RENAME_LDBL(fmin, 3, 3) __attribute_const__;
    302 
    303 double fma(double __x, double __y, double __z);
    304 float fmaf(float __x, float __y, float __z);
    305 long double fmal(long double __x, long double __y, long double __z) __RENAME_LDBL(fma, 3, 21) __VERSIONER_NO_GUARD;
    306 
    307 #define isgreater(x, y) __builtin_isgreater((x), (y))
    308 #define isgreaterequal(x, y) __builtin_isgreaterequal((x), (y))
    309 #define isless(x, y) __builtin_isless((x), (y))
    310 #define islessequal(x, y) __builtin_islessequal((x), (y))
    311 #define islessgreater(x, y) __builtin_islessgreater((x), (y))
    312 #define isunordered(x, y) __builtin_isunordered((x), (y))
    313 
    314 /*
    315  * https://code.google.com/p/android/issues/detail?id=271629
    316  * To be fully compliant with C++, we need to not define these (C doesn't
    317  * specify them either). Exposing these means that isinf and isnan will have a
    318  * return type of int in C++ rather than bool like they're supposed to be.
    319  *
    320  * GNU libstdc++ 4.9 isn't able to handle a standard compliant C library. Its
    321  * <cmath> will `#undef isnan` from math.h and only adds the function overloads
    322  * to the std namespace, making it impossible to use both <cmath> (which gets
    323  * included by a lot of other standard headers) and ::isnan.
    324  */
    325 int (isinf)(double __x) __attribute_const__ __INTRODUCED_IN(21);
    326 int (isnan)(double __x) __attribute_const__;
    327 
    328 /* POSIX extensions. */
    329 
    330 extern int signgam;
    331 
    332 double j0(double __x);
    333 double j1(double __x);
    334 double jn(int __n, double __x);
    335 double y0(double __x);
    336 double y1(double __x);
    337 double yn(int __n, double __x);
    338 
    339 #define M_E		2.7182818284590452354	/* e */
    340 #define M_LOG2E		1.4426950408889634074	/* log 2e */
    341 #define M_LOG10E	0.43429448190325182765	/* log 10e */
    342 #define M_LN2		0.69314718055994530942	/* log e2 */
    343 #define M_LN10		2.30258509299404568402	/* log e10 */
    344 #define M_PI		3.14159265358979323846	/* pi */
    345 #define M_PI_2		1.57079632679489661923	/* pi/2 */
    346 #define M_PI_4		0.78539816339744830962	/* pi/4 */
    347 #define M_1_PI		0.31830988618379067154	/* 1/pi */
    348 #define M_2_PI		0.63661977236758134308	/* 2/pi */
    349 #define M_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
    350 #define M_SQRT2		1.41421356237309504880	/* sqrt(2) */
    351 #define M_SQRT1_2	0.70710678118654752440	/* 1/sqrt(2) */
    352 
    353 #define MAXFLOAT	((float)3.40282346638528860e+38)
    354 
    355 /* BSD extensions. */
    356 
    357 #if defined(__USE_BSD)
    358 #define HUGE MAXFLOAT
    359 #endif
    360 
    361 /* Extensions in both BSD and GNU. */
    362 
    363 #if defined(__USE_BSD) || defined(__USE_GNU)
    364 double gamma(double __x);
    365 double scalb(double __x, double __exponent);
    366 double drem(double __x, double __y);
    367 int finite(double __x) __attribute_const__;
    368 int isnanf(float __x) __attribute_const__;
    369 double gamma_r(double __x, int* __sign);
    370 double lgamma_r(double __x, int* __sign);
    371 double significand(double __x);
    372 long double lgammal_r(long double __x, int* __sign) __INTRODUCED_IN(23);
    373 long double significandl(long double __x) __INTRODUCED_IN(21);
    374 float dremf(float __x, float __y);
    375 int finitef(float __x) __attribute_const__;
    376 float gammaf(float __x);
    377 float j0f(float __x);
    378 float j1f(float __x);
    379 float jnf(int __n, float __x);
    380 float scalbf(float __x, float __exponent);
    381 float y0f(float __x);
    382 float y1f(float __x);
    383 float ynf(int __n, float __x);
    384 float gammaf_r(float __x, int* __sign);
    385 float lgammaf_r(float __x, int* __sign);
    386 float significandf(float __x);
    387 void sincos(double __x, double* __sin, double* __cos);
    388 void sincosf(float __x, float* __sin, float* __cos);
    389 void sincosl(long double __x, long double* __sin, long double* __cos);
    390 #endif
    391 
    392 /* GNU extensions. */
    393 
    394 #if defined(__USE_GNU)
    395 #define M_El            2.718281828459045235360287471352662498L /* e */
    396 #define M_LOG2El        1.442695040888963407359924681001892137L /* log 2e */
    397 #define M_LOG10El       0.434294481903251827651128918916605082L /* log 10e */
    398 #define M_LN2l          0.693147180559945309417232121458176568L /* log e2 */
    399 #define M_LN10l         2.302585092994045684017991454684364208L /* log e10 */
    400 #define M_PIl           3.141592653589793238462643383279502884L /* pi */
    401 #define M_PI_2l         1.570796326794896619231321691639751442L /* pi/2 */
    402 #define M_PI_4l         0.785398163397448309615660845819875721L /* pi/4 */
    403 #define M_1_PIl         0.318309886183790671537767526745028724L /* 1/pi */
    404 #define M_2_PIl         0.636619772367581343075535053490057448L /* 2/pi */
    405 #define M_2_SQRTPIl     1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
    406 #define M_SQRT2l        1.414213562373095048801688724209698079L /* sqrt(2) */
    407 #define M_SQRT1_2l      0.707106781186547524400844362104849039L /* 1/sqrt(2) */
    408 #endif
    409 
    410 __END_DECLS
    411 
    412 #endif
    413