| 1 |
#ifndef _MATH_H |
| 2 |
#define _MATH_H |
| 3 |
|
| 4 |
#ifdef __cplusplus |
| 5 |
extern "C" { |
| 6 |
#endif |
| 7 |
|
| 8 |
#include <features.h> |
| 9 |
|
| 10 |
#define __NEED_float_t |
| 11 |
#define __NEED_double_t |
| 12 |
#include <bits/alltypes.h> |
| 13 |
|
| 14 |
#if 100*__GNUC__+__GNUC_MINOR__ >= 303 |
| 15 |
#define NAN __builtin_nanf("") |
| 16 |
#define INFINITY __builtin_inff() |
| 17 |
#else |
| 18 |
#define NAN (0.0f/0.0f) |
| 19 |
#define INFINITY 1e5000f |
| 20 |
#endif |
| 21 |
|
| 22 |
#define HUGE_VALF INFINITY |
| 23 |
#define HUGE_VAL ((double)INFINITY) |
| 24 |
#define HUGE_VALL ((long double)INFINITY) |
| 25 |
|
| 26 |
#define MATH_ERRNO 1 |
| 27 |
#define MATH_ERREXCEPT 2 |
| 28 |
#define math_errhandling 2 |
| 29 |
|
| 30 |
#define FP_ILOGBNAN (-1-0x7fffffff) |
| 31 |
#define FP_ILOGB0 FP_ILOGBNAN |
| 32 |
|
| 33 |
#define FP_NAN 0 |
| 34 |
#define FP_INFINITE 1 |
| 35 |
#define FP_ZERO 2 |
| 36 |
#define FP_SUBNORMAL 3 |
| 37 |
#define FP_NORMAL 4 |
| 38 |
|
| 39 |
#ifdef __FP_FAST_FMA |
| 40 |
#define FP_FAST_FMA 1 |
| 41 |
#endif |
| 42 |
|
| 43 |
#ifdef __FP_FAST_FMAF |
| 44 |
#define FP_FAST_FMAF 1 |
| 45 |
#endif |
| 46 |
|
| 47 |
#ifdef __FP_FAST_FMAL |
| 48 |
#define FP_FAST_FMAL 1 |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */ |
| 52 |
int __fpclassify(double); |
| 53 |
int __fpclassifyf(float); |
| 54 |
int __fpclassifyl(long double); |
| 55 |
|
| 56 |
static __inline unsigned __FLOAT_BITS(float __f) |
| 57 |
{ |
| 58 |
union {float __f; unsigned __i;} __u; |
| 59 |
__u.__f = __f; |
| 60 |
return __u.__i; |
| 61 |
} |
| 62 |
static __inline unsigned long long __DOUBLE_BITS(double __f) |
| 63 |
{ |
| 64 |
union {double __f; unsigned long long __i;} __u; |
| 65 |
__u.__f = __f; |
| 66 |
return __u.__i; |
| 67 |
} |
| 68 |
|
| 69 |
#define fpclassify(x) ( \ |
| 70 |
sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ |
| 71 |
sizeof(x) == sizeof(double) ? __fpclassify(x) : \ |
| 72 |
__fpclassifyl(x) ) |
| 73 |
|
| 74 |
#define isinf(x) ( \ |
| 75 |
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ |
| 76 |
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ |
| 77 |
__fpclassifyl(x) == FP_INFINITE) |
| 78 |
|
| 79 |
#define isnan(x) ( \ |
| 80 |
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ |
| 81 |
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ |
| 82 |
__fpclassifyl(x) == FP_NAN) |
| 83 |
|
| 84 |
#define isnormal(x) ( \ |
| 85 |
sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ |
| 86 |
sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ |
| 87 |
__fpclassifyl(x) == FP_NORMAL) |
| 88 |
|
| 89 |
#define isfinite(x) ( \ |
| 90 |
sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ |
| 91 |
sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ |
| 92 |
__fpclassifyl(x) > FP_INFINITE) |
| 93 |
|
| 94 |
int __signbit(double); |
| 95 |
int __signbitf(float); |
| 96 |
int __signbitl(long double); |
| 97 |
|
| 98 |
#define signbit(x) ( \ |
| 99 |
sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ |
| 100 |
sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ |
| 101 |
__signbitl(x) ) |
| 102 |
|
| 103 |
#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) |
| 104 |
|
| 105 |
#define __ISREL_DEF(rel, op, type) \ |
| 106 |
static __inline int __is##rel(type __x, type __y) \ |
| 107 |
{ return !isunordered(__x,__y) && __x op __y; } |
| 108 |
|
| 109 |
__ISREL_DEF(lessf, <, float_t) |
| 110 |
__ISREL_DEF(less, <, double_t) |
| 111 |
__ISREL_DEF(lessl, <, long double) |
| 112 |
__ISREL_DEF(lessequalf, <=, float_t) |
| 113 |
__ISREL_DEF(lessequal, <=, double_t) |
| 114 |
__ISREL_DEF(lessequall, <=, long double) |
| 115 |
__ISREL_DEF(lessgreaterf, !=, float_t) |
| 116 |
__ISREL_DEF(lessgreater, !=, double_t) |
| 117 |
__ISREL_DEF(lessgreaterl, !=, long double) |
| 118 |
__ISREL_DEF(greaterf, >, float_t) |
| 119 |
__ISREL_DEF(greater, >, double_t) |
| 120 |
__ISREL_DEF(greaterl, >, long double) |
| 121 |
__ISREL_DEF(greaterequalf, >=, float_t) |
| 122 |
__ISREL_DEF(greaterequal, >=, double_t) |
| 123 |
__ISREL_DEF(greaterequall, >=, long double) |
| 124 |
|
| 125 |
#define __tg_pred_2(x, y, p) ( \ |
| 126 |
sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ |
| 127 |
sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ |
| 128 |
p##l(x, y) ) |
| 129 |
|
| 130 |
#define isless(x, y) __tg_pred_2(x, y, __isless) |
| 131 |
#define islessequal(x, y) __tg_pred_2(x, y, __islessequal) |
| 132 |
#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) |
| 133 |
#define isgreater(x, y) __tg_pred_2(x, y, __isgreater) |
| 134 |
#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) |
| 135 |
#else |
| 136 |
#define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \ |
| 137 |
FP_NORMAL, FP_SUBNORMAL, \ |
| 138 |
FP_ZERO, x)) |
| 139 |
#define isinf(x) (__builtin_isinf(x)) |
| 140 |
#define isnan(x) (__builtin_isnan(x)) |
| 141 |
#define isnormal(x) (__builtin_isnormal(x)) |
| 142 |
#define isfinite(x) (__builtin_isfinite(x)) |
| 143 |
#define signbit(x) (__builtin_signbit(x)) |
| 144 |
#define isunordered(x, y) (__builtin_isunordered(x, y)) |
| 145 |
#define isless(x, y) (__builtin_isless(x, y)) |
| 146 |
#define islessequal(x, y) (__builtin_islessequal(x, y)) |
| 147 |
#define islessgreater(x, y) (__builtin_islessgreater(x, y)) |
| 148 |
#define isgreater(x, y) (__builtin_isgreater(x, y)) |
| 149 |
#define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y)) |
| 150 |
#endif |
| 151 |
|
| 152 |
double acos(double); |
| 153 |
float acosf(float); |
| 154 |
long double acosl(long double); |
| 155 |
|
| 156 |
double acosh(double); |
| 157 |
float acoshf(float); |
| 158 |
long double acoshl(long double); |
| 159 |
|
| 160 |
double asin(double); |
| 161 |
float asinf(float); |
| 162 |
long double asinl(long double); |
| 163 |
|
| 164 |
double asinh(double); |
| 165 |
float asinhf(float); |
| 166 |
long double asinhl(long double); |
| 167 |
|
| 168 |
double atan(double); |
| 169 |
float atanf(float); |
| 170 |
long double atanl(long double); |
| 171 |
|
| 172 |
double atan2(double, double); |
| 173 |
float atan2f(float, float); |
| 174 |
long double atan2l(long double, long double); |
| 175 |
|
| 176 |
double atanh(double); |
| 177 |
float atanhf(float); |
| 178 |
long double atanhl(long double); |
| 179 |
|
| 180 |
double cbrt(double); |
| 181 |
float cbrtf(float); |
| 182 |
long double cbrtl(long double); |
| 183 |
|
| 184 |
double ceil(double); |
| 185 |
float ceilf(float); |
| 186 |
long double ceill(long double); |
| 187 |
|
| 188 |
double copysign(double, double); |
| 189 |
float copysignf(float, float); |
| 190 |
long double copysignl(long double, long double); |
| 191 |
|
| 192 |
double cos(double); |
| 193 |
float cosf(float); |
| 194 |
long double cosl(long double); |
| 195 |
|
| 196 |
double cosh(double); |
| 197 |
float coshf(float); |
| 198 |
long double coshl(long double); |
| 199 |
|
| 200 |
double erf(double); |
| 201 |
float erff(float); |
| 202 |
long double erfl(long double); |
| 203 |
|
| 204 |
double erfc(double); |
| 205 |
float erfcf(float); |
| 206 |
long double erfcl(long double); |
| 207 |
|
| 208 |
double exp(double); |
| 209 |
float expf(float); |
| 210 |
long double expl(long double); |
| 211 |
|
| 212 |
double exp2(double); |
| 213 |
float exp2f(float); |
| 214 |
long double exp2l(long double); |
| 215 |
|
| 216 |
double expm1(double); |
| 217 |
float expm1f(float); |
| 218 |
long double expm1l(long double); |
| 219 |
|
| 220 |
double fabs(double); |
| 221 |
float fabsf(float); |
| 222 |
long double fabsl(long double); |
| 223 |
|
| 224 |
double fdim(double, double); |
| 225 |
float fdimf(float, float); |
| 226 |
long double fdiml(long double, long double); |
| 227 |
|
| 228 |
double floor(double); |
| 229 |
float floorf(float); |
| 230 |
long double floorl(long double); |
| 231 |
|
| 232 |
double fma(double, double, double); |
| 233 |
float fmaf(float, float, float); |
| 234 |
long double fmal(long double, long double, long double); |
| 235 |
|
| 236 |
double fmax(double, double); |
| 237 |
float fmaxf(float, float); |
| 238 |
long double fmaxl(long double, long double); |
| 239 |
|
| 240 |
double fmin(double, double); |
| 241 |
float fminf(float, float); |
| 242 |
long double fminl(long double, long double); |
| 243 |
|
| 244 |
double fmod(double, double); |
| 245 |
float fmodf(float, float); |
| 246 |
long double fmodl(long double, long double); |
| 247 |
|
| 248 |
double frexp(double, int *); |
| 249 |
float frexpf(float, int *); |
| 250 |
long double frexpl(long double, int *); |
| 251 |
|
| 252 |
double hypot(double, double); |
| 253 |
float hypotf(float, float); |
| 254 |
long double hypotl(long double, long double); |
| 255 |
|
| 256 |
int ilogb(double); |
| 257 |
int ilogbf(float); |
| 258 |
int ilogbl(long double); |
| 259 |
|
| 260 |
double ldexp(double, int); |
| 261 |
float ldexpf(float, int); |
| 262 |
long double ldexpl(long double, int); |
| 263 |
|
| 264 |
double lgamma(double); |
| 265 |
float lgammaf(float); |
| 266 |
long double lgammal(long double); |
| 267 |
|
| 268 |
long long llrint(double); |
| 269 |
long long llrintf(float); |
| 270 |
long long llrintl(long double); |
| 271 |
|
| 272 |
long long llround(double); |
| 273 |
long long llroundf(float); |
| 274 |
long long llroundl(long double); |
| 275 |
|
| 276 |
double log(double); |
| 277 |
float logf(float); |
| 278 |
long double logl(long double); |
| 279 |
|
| 280 |
double log10(double); |
| 281 |
float log10f(float); |
| 282 |
long double log10l(long double); |
| 283 |
|
| 284 |
double log1p(double); |
| 285 |
float log1pf(float); |
| 286 |
long double log1pl(long double); |
| 287 |
|
| 288 |
double log2(double); |
| 289 |
float log2f(float); |
| 290 |
long double log2l(long double); |
| 291 |
|
| 292 |
double logb(double); |
| 293 |
float logbf(float); |
| 294 |
long double logbl(long double); |
| 295 |
|
| 296 |
long lrint(double); |
| 297 |
long lrintf(float); |
| 298 |
long lrintl(long double); |
| 299 |
|
| 300 |
long lround(double); |
| 301 |
long lroundf(float); |
| 302 |
long lroundl(long double); |
| 303 |
|
| 304 |
double modf(double, double *); |
| 305 |
float modff(float, float *); |
| 306 |
long double modfl(long double, long double *); |
| 307 |
|
| 308 |
double nan(const char *); |
| 309 |
float nanf(const char *); |
| 310 |
long double nanl(const char *); |
| 311 |
|
| 312 |
double nearbyint(double); |
| 313 |
float nearbyintf(float); |
| 314 |
long double nearbyintl(long double); |
| 315 |
|
| 316 |
double nextafter(double, double); |
| 317 |
float nextafterf(float, float); |
| 318 |
long double nextafterl(long double, long double); |
| 319 |
|
| 320 |
double nexttoward(double, long double); |
| 321 |
float nexttowardf(float, long double); |
| 322 |
long double nexttowardl(long double, long double); |
| 323 |
|
| 324 |
double pow(double, double); |
| 325 |
float powf(float, float); |
| 326 |
long double powl(long double, long double); |
| 327 |
|
| 328 |
double remainder(double, double); |
| 329 |
float remainderf(float, float); |
| 330 |
long double remainderl(long double, long double); |
| 331 |
|
| 332 |
double remquo(double, double, int *); |
| 333 |
float remquof(float, float, int *); |
| 334 |
long double remquol(long double, long double, int *); |
| 335 |
|
| 336 |
double rint(double); |
| 337 |
float rintf(float); |
| 338 |
long double rintl(long double); |
| 339 |
|
| 340 |
double round(double); |
| 341 |
float roundf(float); |
| 342 |
long double roundl(long double); |
| 343 |
|
| 344 |
double scalbln(double, long); |
| 345 |
float scalblnf(float, long); |
| 346 |
long double scalblnl(long double, long); |
| 347 |
|
| 348 |
double scalbn(double, int); |
| 349 |
float scalbnf(float, int); |
| 350 |
long double scalbnl(long double, int); |
| 351 |
|
| 352 |
double sin(double); |
| 353 |
float sinf(float); |
| 354 |
long double sinl(long double); |
| 355 |
|
| 356 |
double sinh(double); |
| 357 |
float sinhf(float); |
| 358 |
long double sinhl(long double); |
| 359 |
|
| 360 |
double sqrt(double); |
| 361 |
float sqrtf(float); |
| 362 |
long double sqrtl(long double); |
| 363 |
|
| 364 |
double tan(double); |
| 365 |
float tanf(float); |
| 366 |
long double tanl(long double); |
| 367 |
|
| 368 |
double tanh(double); |
| 369 |
float tanhf(float); |
| 370 |
long double tanhl(long double); |
| 371 |
|
| 372 |
double tgamma(double); |
| 373 |
float tgammaf(float); |
| 374 |
long double tgammal(long double); |
| 375 |
|
| 376 |
double trunc(double); |
| 377 |
float truncf(float); |
| 378 |
long double truncl(long double); |
| 379 |
|
| 380 |
|
| 381 |
#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) |
| 382 |
#undef MAXFLOAT |
| 383 |
#define MAXFLOAT 3.40282346638528859812e+38F |
| 384 |
#endif |
| 385 |
|
| 386 |
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 387 |
#define M_E 2.7182818284590452354 /* e */ |
| 388 |
#define M_LOG2E 1.4426950408889634074 /* log_2 e */ |
| 389 |
#define M_LOG10E 0.43429448190325182765 /* log_10 e */ |
| 390 |
#define M_LN2 0.69314718055994530942 /* log_e 2 */ |
| 391 |
#define M_LN10 2.30258509299404568402 /* log_e 10 */ |
| 392 |
#define M_PI 3.14159265358979323846 /* pi */ |
| 393 |
#define M_PI_2 1.57079632679489661923 /* pi/2 */ |
| 394 |
#define M_PI_4 0.78539816339744830962 /* pi/4 */ |
| 395 |
#define M_1_PI 0.31830988618379067154 /* 1/pi */ |
| 396 |
#define M_2_PI 0.63661977236758134308 /* 2/pi */ |
| 397 |
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ |
| 398 |
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ |
| 399 |
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ |
| 400 |
|
| 401 |
extern int signgam; |
| 402 |
|
| 403 |
double j0(double); |
| 404 |
double j1(double); |
| 405 |
double jn(int, double); |
| 406 |
|
| 407 |
double y0(double); |
| 408 |
double y1(double); |
| 409 |
double yn(int, double); |
| 410 |
#endif |
| 411 |
|
| 412 |
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 413 |
#define HUGE 3.40282346638528859812e+38F |
| 414 |
|
| 415 |
double drem(double, double); |
| 416 |
float dremf(float, float); |
| 417 |
|
| 418 |
int finite(double); |
| 419 |
int finitef(float); |
| 420 |
|
| 421 |
double scalb(double, double); |
| 422 |
float scalbf(float, float); |
| 423 |
|
| 424 |
double significand(double); |
| 425 |
float significandf(float); |
| 426 |
|
| 427 |
double lgamma_r(double, int*); |
| 428 |
float lgammaf_r(float, int*); |
| 429 |
|
| 430 |
float j0f(float); |
| 431 |
float j1f(float); |
| 432 |
float jnf(int, float); |
| 433 |
|
| 434 |
float y0f(float); |
| 435 |
float y1f(float); |
| 436 |
float ynf(int, float); |
| 437 |
#endif |
| 438 |
|
| 439 |
#ifdef _GNU_SOURCE |
| 440 |
long double lgammal_r(long double, int*); |
| 441 |
|
| 442 |
void sincos(double, double*, double*); |
| 443 |
void sincosf(float, float*, float*); |
| 444 |
void sincosl(long double, long double*, long double*); |
| 445 |
|
| 446 |
double exp10(double); |
| 447 |
float exp10f(float); |
| 448 |
long double exp10l(long double); |
| 449 |
|
| 450 |
double pow10(double); |
| 451 |
float pow10f(float); |
| 452 |
long double pow10l(long double); |
| 453 |
#endif |
| 454 |
|
| 455 |
#ifdef __cplusplus |
| 456 |
} |
| 457 |
#endif |
| 458 |
|
| 459 |
#endif |