1 // -*- C++ -*- 2 //===---------------------------- cmath -----------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef _LIBCPP_CMATH 12 #define _LIBCPP_CMATH 13 14 /* 15 cmath synopsis 16 17 Macros: 18 19 HUGE_VAL 20 HUGE_VALF // C99 21 HUGE_VALL // C99 22 INFINITY // C99 23 NAN // C99 24 FP_INFINITE // C99 25 FP_NAN // C99 26 FP_NORMAL // C99 27 FP_SUBNORMAL // C99 28 FP_ZERO // C99 29 FP_FAST_FMA // C99 30 FP_FAST_FMAF // C99 31 FP_FAST_FMAL // C99 32 FP_ILOGB0 // C99 33 FP_ILOGBNAN // C99 34 MATH_ERRNO // C99 35 MATH_ERREXCEPT // C99 36 math_errhandling // C99 37 38 namespace std 39 { 40 41 Types: 42 43 float_t // C99 44 double_t // C99 45 46 // C90 47 48 floating_point abs(floating_point x); 49 50 floating_point acos (arithmetic x); 51 float acosf(float x); 52 long double acosl(long double x); 53 54 floating_point asin (arithmetic x); 55 float asinf(float x); 56 long double asinl(long double x); 57 58 floating_point atan (arithmetic x); 59 float atanf(float x); 60 long double atanl(long double x); 61 62 floating_point atan2 (arithmetic y, arithmetic x); 63 float atan2f(float y, float x); 64 long double atan2l(long double y, long double x); 65 66 floating_point ceil (arithmetic x); 67 float ceilf(float x); 68 long double ceill(long double x); 69 70 floating_point cos (arithmetic x); 71 float cosf(float x); 72 long double cosl(long double x); 73 74 floating_point cosh (arithmetic x); 75 float coshf(float x); 76 long double coshl(long double x); 77 78 floating_point exp (arithmetic x); 79 float expf(float x); 80 long double expl(long double x); 81 82 floating_point fabs (arithmetic x); 83 float fabsf(float x); 84 long double fabsl(long double x); 85 86 floating_point floor (arithmetic x); 87 float floorf(float x); 88 long double floorl(long double x); 89 90 floating_point fmod (arithmetic x, arithmetic y); 91 float fmodf(float x, float y); 92 long double fmodl(long double x, long double y); 93 94 floating_point frexp (arithmetic value, int* exp); 95 float frexpf(float value, int* exp); 96 long double frexpl(long double value, int* exp); 97 98 floating_point ldexp (arithmetic value, int exp); 99 float ldexpf(float value, int exp); 100 long double ldexpl(long double value, int exp); 101 102 floating_point log (arithmetic x); 103 float logf(float x); 104 long double logl(long double x); 105 106 floating_point log10 (arithmetic x); 107 float log10f(float x); 108 long double log10l(long double x); 109 110 floating_point modf (floating_point value, floating_point* iptr); 111 float modff(float value, float* iptr); 112 long double modfl(long double value, long double* iptr); 113 114 floating_point pow (arithmetic x, arithmetic y); 115 float powf(float x, float y); 116 long double powl(long double x, long double y); 117 118 floating_point sin (arithmetic x); 119 float sinf(float x); 120 long double sinl(long double x); 121 122 floating_point sinh (arithmetic x); 123 float sinhf(float x); 124 long double sinhl(long double x); 125 126 floating_point sqrt (arithmetic x); 127 float sqrtf(float x); 128 long double sqrtl(long double x); 129 130 floating_point tan (arithmetic x); 131 float tanf(float x); 132 long double tanl(long double x); 133 134 floating_point tanh (arithmetic x); 135 float tanhf(float x); 136 long double tanhl(long double x); 137 138 // C99 139 140 bool signbit(arithmetic x); 141 142 int fpclassify(arithmetic x); 143 144 bool isfinite(arithmetic x); 145 bool isinf(arithmetic x); 146 bool isnan(arithmetic x); 147 bool isnormal(arithmetic x); 148 149 bool isgreater(arithmetic x, arithmetic y); 150 bool isgreaterequal(arithmetic x, arithmetic y); 151 bool isless(arithmetic x, arithmetic y); 152 bool islessequal(arithmetic x, arithmetic y); 153 bool islessgreater(arithmetic x, arithmetic y); 154 bool isunordered(arithmetic x, arithmetic y); 155 156 floating_point acosh (arithmetic x); 157 float acoshf(float x); 158 long double acoshl(long double x); 159 160 floating_point asinh (arithmetic x); 161 float asinhf(float x); 162 long double asinhl(long double x); 163 164 floating_point atanh (arithmetic x); 165 float atanhf(float x); 166 long double atanhl(long double x); 167 168 floating_point cbrt (arithmetic x); 169 float cbrtf(float x); 170 long double cbrtl(long double x); 171 172 floating_point copysign (arithmetic x, arithmetic y); 173 float copysignf(float x, float y); 174 long double copysignl(long double x, long double y); 175 176 floating_point erf (arithmetic x); 177 float erff(float x); 178 long double erfl(long double x); 179 180 floating_point erfc (arithmetic x); 181 float erfcf(float x); 182 long double erfcl(long double x); 183 184 floating_point exp2 (arithmetic x); 185 float exp2f(float x); 186 long double exp2l(long double x); 187 188 floating_point expm1 (arithmetic x); 189 float expm1f(float x); 190 long double expm1l(long double x); 191 192 floating_point fdim (arithmetic x, arithmetic y); 193 float fdimf(float x, float y); 194 long double fdiml(long double x, long double y); 195 196 floating_point fma (arithmetic x, arithmetic y, arithmetic z); 197 float fmaf(float x, float y, float z); 198 long double fmal(long double x, long double y, long double z); 199 200 floating_point fmax (arithmetic x, arithmetic y); 201 float fmaxf(float x, float y); 202 long double fmaxl(long double x, long double y); 203 204 floating_point fmin (arithmetic x, arithmetic y); 205 float fminf(float x, float y); 206 long double fminl(long double x, long double y); 207 208 floating_point hypot (arithmetic x, arithmetic y); 209 float hypotf(float x, float y); 210 long double hypotl(long double x, long double y); 211 212 double hypot(double x, double y, double z); // C++17 213 float hypot(float x, float y, float z); // C++17 214 long double hypot(long double x, long double y, long double z); // C++17 215 216 int ilogb (arithmetic x); 217 int ilogbf(float x); 218 int ilogbl(long double x); 219 220 floating_point lgamma (arithmetic x); 221 float lgammaf(float x); 222 long double lgammal(long double x); 223 224 long long llrint (arithmetic x); 225 long long llrintf(float x); 226 long long llrintl(long double x); 227 228 long long llround (arithmetic x); 229 long long llroundf(float x); 230 long long llroundl(long double x); 231 232 floating_point log1p (arithmetic x); 233 float log1pf(float x); 234 long double log1pl(long double x); 235 236 floating_point log2 (arithmetic x); 237 float log2f(float x); 238 long double log2l(long double x); 239 240 floating_point logb (arithmetic x); 241 float logbf(float x); 242 long double logbl(long double x); 243 244 long lrint (arithmetic x); 245 long lrintf(float x); 246 long lrintl(long double x); 247 248 long lround (arithmetic x); 249 long lroundf(float x); 250 long lroundl(long double x); 251 252 double nan (const char* str); 253 float nanf(const char* str); 254 long double nanl(const char* str); 255 256 floating_point nearbyint (arithmetic x); 257 float nearbyintf(float x); 258 long double nearbyintl(long double x); 259 260 floating_point nextafter (arithmetic x, arithmetic y); 261 float nextafterf(float x, float y); 262 long double nextafterl(long double x, long double y); 263 264 floating_point nexttoward (arithmetic x, long double y); 265 float nexttowardf(float x, long double y); 266 long double nexttowardl(long double x, long double y); 267 268 floating_point remainder (arithmetic x, arithmetic y); 269 float remainderf(float x, float y); 270 long double remainderl(long double x, long double y); 271 272 floating_point remquo (arithmetic x, arithmetic y, int* pquo); 273 float remquof(float x, float y, int* pquo); 274 long double remquol(long double x, long double y, int* pquo); 275 276 floating_point rint (arithmetic x); 277 float rintf(float x); 278 long double rintl(long double x); 279 280 floating_point round (arithmetic x); 281 float roundf(float x); 282 long double roundl(long double x); 283 284 floating_point scalbln (arithmetic x, long ex); 285 float scalblnf(float x, long ex); 286 long double scalblnl(long double x, long ex); 287 288 floating_point scalbn (arithmetic x, int ex); 289 float scalbnf(float x, int ex); 290 long double scalbnl(long double x, int ex); 291 292 floating_point tgamma (arithmetic x); 293 float tgammaf(float x); 294 long double tgammal(long double x); 295 296 floating_point trunc (arithmetic x); 297 float truncf(float x); 298 long double truncl(long double x); 299 300 } // std 301 302 */ 303 304 #include <__config> 305 #include <math.h> 306 #include <version> 307 308 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 309 #pragma GCC system_header 310 #endif 311 312 _LIBCPP_BEGIN_NAMESPACE_STD 313 314 using ::signbit; 315 using ::fpclassify; 316 using ::isfinite; 317 using ::isinf; 318 using ::isnan; 319 using ::isnormal; 320 using ::isgreater; 321 using ::isgreaterequal; 322 using ::isless; 323 using ::islessequal; 324 using ::islessgreater; 325 using ::isunordered; 326 using ::isunordered; 327 328 using ::float_t; 329 using ::double_t; 330 331 #ifndef _AIX 332 using ::abs; 333 #endif 334 335 using ::acos; 336 using ::acosf; 337 using ::asin; 338 using ::asinf; 339 using ::atan; 340 using ::atanf; 341 using ::atan2; 342 using ::atan2f; 343 using ::ceil; 344 using ::ceilf; 345 using ::cos; 346 using ::cosf; 347 using ::cosh; 348 using ::coshf; 349 350 using ::exp; 351 using ::expf; 352 353 using ::fabs; 354 using ::fabsf; 355 using ::floor; 356 using ::floorf; 357 358 using ::fmod; 359 using ::fmodf; 360 361 using ::frexp; 362 using ::frexpf; 363 using ::ldexp; 364 using ::ldexpf; 365 366 using ::log; 367 using ::logf; 368 369 using ::log10; 370 using ::log10f; 371 using ::modf; 372 using ::modff; 373 374 using ::pow; 375 using ::powf; 376 377 using ::sin; 378 using ::sinf; 379 using ::sinh; 380 using ::sinhf; 381 382 using ::sqrt; 383 using ::sqrtf; 384 using ::tan; 385 using ::tanf; 386 387 using ::tanh; 388 using ::tanhf; 389 390 using ::acosh; 391 using ::acoshf; 392 using ::asinh; 393 using ::asinhf; 394 using ::atanh; 395 using ::atanhf; 396 using ::cbrt; 397 using ::cbrtf; 398 399 using ::copysign; 400 using ::copysignf; 401 402 using ::erf; 403 using ::erff; 404 using ::erfc; 405 using ::erfcf; 406 using ::exp2; 407 using ::exp2f; 408 using ::expm1; 409 using ::expm1f; 410 using ::fdim; 411 using ::fdimf; 412 using ::fmaf; 413 using ::fma; 414 using ::fmax; 415 using ::fmaxf; 416 using ::fmin; 417 using ::fminf; 418 using ::hypot; 419 using ::hypotf; 420 using ::ilogb; 421 using ::ilogbf; 422 using ::lgamma; 423 using ::lgammaf; 424 using ::llrint; 425 using ::llrintf; 426 using ::llround; 427 using ::llroundf; 428 using ::log1p; 429 using ::log1pf; 430 using ::log2; 431 using ::log2f; 432 using ::logb; 433 using ::logbf; 434 using ::lrint; 435 using ::lrintf; 436 using ::lround; 437 using ::lroundf; 438 439 using ::nan; 440 using ::nanf; 441 442 using ::nearbyint; 443 using ::nearbyintf; 444 using ::nextafter; 445 using ::nextafterf; 446 using ::nexttoward; 447 using ::nexttowardf; 448 using ::remainder; 449 using ::remainderf; 450 using ::remquo; 451 using ::remquof; 452 using ::rint; 453 using ::rintf; 454 using ::round; 455 using ::roundf; 456 using ::scalbln; 457 using ::scalblnf; 458 using ::scalbn; 459 using ::scalbnf; 460 using ::tgamma; 461 using ::tgammaf; 462 using ::trunc; 463 using ::truncf; 464 465 using ::acosl; 466 using ::asinl; 467 using ::atanl; 468 using ::atan2l; 469 using ::ceill; 470 using ::cosl; 471 using ::coshl; 472 using ::expl; 473 using ::fabsl; 474 using ::floorl; 475 using ::fmodl; 476 using ::frexpl; 477 using ::ldexpl; 478 using ::logl; 479 using ::log10l; 480 using ::modfl; 481 using ::powl; 482 using ::sinl; 483 using ::sinhl; 484 using ::sqrtl; 485 using ::tanl; 486 487 using ::tanhl; 488 using ::acoshl; 489 using ::asinhl; 490 using ::atanhl; 491 using ::cbrtl; 492 493 using ::copysignl; 494 495 using ::erfl; 496 using ::erfcl; 497 using ::exp2l; 498 using ::expm1l; 499 using ::fdiml; 500 using ::fmal; 501 using ::fmaxl; 502 using ::fminl; 503 using ::hypotl; 504 using ::ilogbl; 505 using ::lgammal; 506 using ::llrintl; 507 using ::llroundl; 508 using ::log1pl; 509 using ::log2l; 510 using ::logbl; 511 using ::lrintl; 512 using ::lroundl; 513 using ::nanl; 514 using ::nearbyintl; 515 using ::nextafterl; 516 using ::nexttowardl; 517 using ::remainderl; 518 using ::remquol; 519 using ::rintl; 520 using ::roundl; 521 using ::scalblnl; 522 using ::scalbnl; 523 using ::tgammal; 524 using ::truncl; 525 526 #if _LIBCPP_STD_VER > 14 527 inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } 528 inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } 529 inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } 530 531 template <class _A1, class _A2, class _A3> 532 inline _LIBCPP_INLINE_VISIBILITY 533 typename __lazy_enable_if 534 < 535 is_arithmetic<_A1>::value && 536 is_arithmetic<_A2>::value && 537 is_arithmetic<_A3>::value, 538 __promote<_A1, _A2, _A3> 539 >::type 540 hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT 541 { 542 typedef typename __promote<_A1, _A2, _A3>::type __result_type; 543 static_assert((!(is_same<_A1, __result_type>::value && 544 is_same<_A2, __result_type>::value && 545 is_same<_A3, __result_type>::value)), ""); 546 return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); 547 } 548 #endif 549 550 template <class _A1> 551 _LIBCPP_INLINE_VISIBILITY 552 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 553 __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT 554 { 555 #if __has_builtin(__builtin_isnan) 556 return __builtin_isnan(__lcpp_x); 557 #else 558 return isnan(__lcpp_x); 559 #endif 560 } 561 562 template <class _A1> 563 _LIBCPP_INLINE_VISIBILITY 564 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 565 __libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT 566 { 567 return isnan(__lcpp_x); 568 } 569 570 template <class _A1> 571 _LIBCPP_INLINE_VISIBILITY 572 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 573 __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT 574 { 575 #if __has_builtin(__builtin_isinf) 576 return __builtin_isinf(__lcpp_x); 577 #else 578 return isinf(__lcpp_x); 579 #endif 580 } 581 582 template <class _A1> 583 _LIBCPP_INLINE_VISIBILITY 584 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 585 __libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT 586 { 587 return isinf(__lcpp_x); 588 } 589 590 template <class _A1> 591 _LIBCPP_INLINE_VISIBILITY 592 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 593 __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT 594 { 595 #if __has_builtin(__builtin_isfinite) 596 return __builtin_isfinite(__lcpp_x); 597 #else 598 return isfinite(__lcpp_x); 599 #endif 600 } 601 602 template <class _A1> 603 _LIBCPP_INLINE_VISIBILITY 604 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 605 __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT 606 { 607 return isfinite(__lcpp_x); 608 } 609 610 _LIBCPP_END_NAMESPACE_STD 611 612 #endif // _LIBCPP_CMATH 613