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 #ifndef __sun__ 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 #endif // __sun__ 350 351 using ::exp; 352 using ::expf; 353 354 #ifndef __sun__ 355 using ::fabs; 356 using ::fabsf; 357 using ::floor; 358 using ::floorf; 359 #endif //__sun__ 360 361 using ::fmod; 362 using ::fmodf; 363 364 #ifndef __sun__ 365 using ::frexp; 366 using ::frexpf; 367 using ::ldexp; 368 using ::ldexpf; 369 #endif // __sun__ 370 371 using ::log; 372 using ::logf; 373 374 #ifndef __sun__ 375 using ::log10; 376 using ::log10f; 377 using ::modf; 378 using ::modff; 379 #endif // __sun__ 380 381 using ::pow; 382 using ::powf; 383 384 #ifndef __sun__ 385 using ::sin; 386 using ::sinf; 387 using ::sinh; 388 using ::sinhf; 389 #endif // __sun__ 390 391 using ::sqrt; 392 using ::sqrtf; 393 using ::tan; 394 using ::tanf; 395 396 #ifndef __sun__ 397 using ::tanh; 398 using ::tanhf; 399 400 #ifndef _LIBCPP_MSVCRT 401 using ::acosh; 402 using ::acoshf; 403 using ::asinh; 404 using ::asinhf; 405 using ::atanh; 406 using ::atanhf; 407 using ::cbrt; 408 using ::cbrtf; 409 #endif 410 411 using ::copysign; 412 using ::copysignf; 413 414 #ifndef _LIBCPP_MSVCRT 415 using ::erf; 416 using ::erff; 417 using ::erfc; 418 using ::erfcf; 419 using ::exp2; 420 using ::exp2f; 421 using ::expm1; 422 using ::expm1f; 423 using ::fdim; 424 using ::fdimf; 425 using ::fmaf; 426 using ::fma; 427 using ::fmax; 428 using ::fmaxf; 429 using ::fmin; 430 using ::fminf; 431 using ::hypot; 432 using ::hypotf; 433 using ::ilogb; 434 using ::ilogbf; 435 using ::lgamma; 436 using ::lgammaf; 437 using ::llrint; 438 using ::llrintf; 439 using ::llround; 440 using ::llroundf; 441 using ::log1p; 442 using ::log1pf; 443 using ::log2; 444 using ::log2f; 445 using ::logb; 446 using ::logbf; 447 using ::lrint; 448 using ::lrintf; 449 using ::lround; 450 using ::lroundf; 451 #endif // _LIBCPP_MSVCRT 452 #endif // __sun__ 453 454 #ifndef _LIBCPP_MSVCRT 455 using ::nan; 456 using ::nanf; 457 #endif // _LIBCPP_MSVCRT 458 459 #ifndef __sun__ 460 #ifndef _LIBCPP_MSVCRT 461 using ::nearbyint; 462 using ::nearbyintf; 463 using ::nextafter; 464 using ::nextafterf; 465 using ::nexttoward; 466 using ::nexttowardf; 467 using ::remainder; 468 using ::remainderf; 469 using ::remquo; 470 using ::remquof; 471 using ::rint; 472 using ::rintf; 473 using ::round; 474 using ::roundf; 475 using ::scalbln; 476 using ::scalblnf; 477 using ::scalbn; 478 using ::scalbnf; 479 using ::tgamma; 480 using ::tgammaf; 481 using ::trunc; 482 using ::truncf; 483 #endif // !_LIBCPP_MSVCRT 484 485 using ::acosl; 486 using ::asinl; 487 using ::atanl; 488 using ::atan2l; 489 using ::ceill; 490 using ::cosl; 491 using ::coshl; 492 using ::expl; 493 using ::fabsl; 494 using ::floorl; 495 using ::fmodl; 496 using ::frexpl; 497 using ::ldexpl; 498 using ::logl; 499 using ::log10l; 500 using ::modfl; 501 using ::powl; 502 using ::sinl; 503 using ::sinhl; 504 using ::sqrtl; 505 using ::tanl; 506 507 #ifndef _LIBCPP_MSVCRT 508 using ::tanhl; 509 using ::acoshl; 510 using ::asinhl; 511 using ::atanhl; 512 using ::cbrtl; 513 #endif // !_LIBCPP_MSVCRT 514 515 using ::copysignl; 516 517 #ifndef _LIBCPP_MSVCRT 518 using ::erfl; 519 using ::erfcl; 520 using ::exp2l; 521 using ::expm1l; 522 using ::fdiml; 523 using ::fmal; 524 using ::fmaxl; 525 using ::fminl; 526 using ::hypotl; 527 using ::ilogbl; 528 using ::lgammal; 529 using ::llrintl; 530 using ::llroundl; 531 using ::log1pl; 532 using ::log2l; 533 using ::logbl; 534 using ::lrintl; 535 using ::lroundl; 536 using ::nanl; 537 using ::nearbyintl; 538 using ::nextafterl; 539 using ::nexttowardl; 540 using ::remainderl; 541 using ::remquol; 542 using ::rintl; 543 using ::roundl; 544 using ::scalblnl; 545 using ::scalbnl; 546 using ::tgammal; 547 using ::truncl; 548 #endif // !_LIBCPP_MSVCRT 549 550 #else 551 using ::lgamma; 552 using ::lgammaf; 553 #endif // __sun__ 554 555 #if _LIBCPP_STD_VER > 14 556 inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } 557 inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } 558 inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } 559 560 template <class _A1, class _A2, class _A3> 561 inline _LIBCPP_INLINE_VISIBILITY 562 typename std::__lazy_enable_if 563 < 564 std::is_arithmetic<_A1>::value && 565 std::is_arithmetic<_A2>::value && 566 std::is_arithmetic<_A3>::value, 567 std::__promote<_A1, _A2, _A3> 568 >::type 569 hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT 570 { 571 typedef typename std::__promote<_A1, _A2, _A3>::type __result_type; 572 static_assert((!(std::is_same<_A1, __result_type>::value && 573 std::is_same<_A2, __result_type>::value && 574 std::is_same<_A3, __result_type>::value)), ""); 575 return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); 576 } 577 #endif 578 579 _LIBCPP_END_NAMESPACE_STD 580 581 #endif // _LIBCPP_CMATH 582