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 307 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 308 #pragma GCC system_header 309 #endif 310 311 _LIBCPP_BEGIN_NAMESPACE_STD 312 313 using ::signbit; 314 using ::fpclassify; 315 using ::isfinite; 316 using ::isinf; 317 using ::isnan; 318 using ::isnormal; 319 using ::isgreater; 320 using ::isgreaterequal; 321 using ::isless; 322 using ::islessequal; 323 using ::islessgreater; 324 using ::isunordered; 325 using ::isunordered; 326 327 using ::float_t; 328 using ::double_t; 329 330 #ifndef _AIX 331 using ::abs; 332 #endif 333 334 using ::acos; 335 using ::acosf; 336 using ::asin; 337 using ::asinf; 338 using ::atan; 339 using ::atanf; 340 using ::atan2; 341 using ::atan2f; 342 using ::ceil; 343 using ::ceilf; 344 using ::cos; 345 using ::cosf; 346 using ::cosh; 347 using ::coshf; 348 349 using ::exp; 350 using ::expf; 351 352 using ::fabs; 353 using ::fabsf; 354 using ::floor; 355 using ::floorf; 356 357 using ::fmod; 358 using ::fmodf; 359 360 using ::frexp; 361 using ::frexpf; 362 using ::ldexp; 363 using ::ldexpf; 364 365 using ::log; 366 using ::logf; 367 368 using ::log10; 369 using ::log10f; 370 using ::modf; 371 using ::modff; 372 373 using ::pow; 374 using ::powf; 375 376 using ::sin; 377 using ::sinf; 378 using ::sinh; 379 using ::sinhf; 380 381 using ::sqrt; 382 using ::sqrtf; 383 using ::tan; 384 using ::tanf; 385 386 using ::tanh; 387 using ::tanhf; 388 389 using ::acosh; 390 using ::acoshf; 391 using ::asinh; 392 using ::asinhf; 393 using ::atanh; 394 using ::atanhf; 395 using ::cbrt; 396 using ::cbrtf; 397 398 using ::copysign; 399 using ::copysignf; 400 401 #if !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 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 #endif // !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 439 440 using ::nan; 441 using ::nanf; 442 443 #if !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 444 using ::nearbyint; 445 using ::nearbyintf; 446 using ::nextafter; 447 using ::nextafterf; 448 using ::nexttoward; 449 using ::nexttowardf; 450 using ::remainder; 451 using ::remainderf; 452 using ::remquo; 453 using ::remquof; 454 using ::rint; 455 using ::rintf; 456 using ::round; 457 using ::roundf; 458 using ::scalbln; 459 using ::scalblnf; 460 using ::scalbn; 461 using ::scalbnf; 462 using ::tgamma; 463 using ::tgammaf; 464 using ::trunc; 465 using ::truncf; 466 #endif // !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 467 468 using ::acosl; 469 using ::asinl; 470 using ::atanl; 471 using ::atan2l; 472 using ::ceill; 473 using ::cosl; 474 using ::coshl; 475 using ::expl; 476 using ::fabsl; 477 using ::floorl; 478 using ::fmodl; 479 using ::frexpl; 480 using ::ldexpl; 481 using ::logl; 482 using ::log10l; 483 using ::modfl; 484 using ::powl; 485 using ::sinl; 486 using ::sinhl; 487 using ::sqrtl; 488 using ::tanl; 489 490 using ::tanhl; 491 using ::acoshl; 492 using ::asinhl; 493 using ::atanhl; 494 using ::cbrtl; 495 496 using ::copysignl; 497 498 #if !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 499 using ::erfl; 500 using ::erfcl; 501 using ::exp2l; 502 using ::expm1l; 503 using ::fdiml; 504 using ::fmal; 505 using ::fmaxl; 506 using ::fminl; 507 using ::hypotl; 508 using ::ilogbl; 509 using ::lgammal; 510 using ::llrintl; 511 using ::llroundl; 512 using ::log1pl; 513 using ::log2l; 514 using ::logbl; 515 using ::lrintl; 516 using ::lroundl; 517 using ::nanl; 518 using ::nearbyintl; 519 using ::nextafterl; 520 using ::nexttowardl; 521 using ::remainderl; 522 using ::remquol; 523 using ::rintl; 524 using ::roundl; 525 using ::scalblnl; 526 using ::scalbnl; 527 using ::tgammal; 528 using ::truncl; 529 #endif // !(defined(_LIBCPP_MSVCRT) && ((_VC_CRT_MAJOR_VERSION-0) < 14)) 530 531 #if _LIBCPP_STD_VER > 14 532 inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } 533 inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } 534 inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } 535 536 template <class _A1, class _A2, class _A3> 537 inline _LIBCPP_INLINE_VISIBILITY 538 typename __lazy_enable_if 539 < 540 is_arithmetic<_A1>::value && 541 is_arithmetic<_A2>::value && 542 is_arithmetic<_A3>::value, 543 __promote<_A1, _A2, _A3> 544 >::type 545 hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT 546 { 547 typedef typename __promote<_A1, _A2, _A3>::type __result_type; 548 static_assert((!(is_same<_A1, __result_type>::value && 549 is_same<_A2, __result_type>::value && 550 is_same<_A3, __result_type>::value)), ""); 551 return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); 552 } 553 #endif 554 555 template <class _A1> 556 _LIBCPP_ALWAYS_INLINE 557 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 558 __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT 559 { 560 #if __has_builtin(__builtin_isnan) 561 return __builtin_isnan(__lcpp_x); 562 #else 563 return isnan(__lcpp_x); 564 #endif 565 } 566 567 template <class _A1> 568 _LIBCPP_ALWAYS_INLINE 569 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 570 __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT 571 { 572 return isnan(__lcpp_x); 573 } 574 575 template <class _A1> 576 _LIBCPP_ALWAYS_INLINE 577 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 578 __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT 579 { 580 #if __has_builtin(__builtin_isinf) 581 return __builtin_isinf(__lcpp_x); 582 #else 583 return isinf(__lcpp_x); 584 #endif 585 } 586 587 template <class _A1> 588 _LIBCPP_ALWAYS_INLINE 589 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 590 __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT 591 { 592 return isinf(__lcpp_x); 593 } 594 595 template <class _A1> 596 _LIBCPP_ALWAYS_INLINE 597 _LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 598 __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT 599 { 600 #if __has_builtin(__builtin_isfinite) 601 return __builtin_isfinite(__lcpp_x); 602 #else 603 return isfinite(__lcpp_x); 604 #endif 605 } 606 607 template <class _A1> 608 _LIBCPP_ALWAYS_INLINE 609 _LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 610 __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT 611 { 612 return isfinite(__lcpp_x); 613 } 614 615 _LIBCPP_END_NAMESPACE_STD 616 617 #endif // _LIBCPP_CMATH 618