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