10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===---------------------------- cmath -----------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_CMATH 110b57cec5SDimitry Andric#define _LIBCPP_CMATH 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric cmath synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry AndricMacros: 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric HUGE_VAL 190b57cec5SDimitry Andric HUGE_VALF // C99 200b57cec5SDimitry Andric HUGE_VALL // C99 210b57cec5SDimitry Andric INFINITY // C99 220b57cec5SDimitry Andric NAN // C99 230b57cec5SDimitry Andric FP_INFINITE // C99 240b57cec5SDimitry Andric FP_NAN // C99 250b57cec5SDimitry Andric FP_NORMAL // C99 260b57cec5SDimitry Andric FP_SUBNORMAL // C99 270b57cec5SDimitry Andric FP_ZERO // C99 280b57cec5SDimitry Andric FP_FAST_FMA // C99 290b57cec5SDimitry Andric FP_FAST_FMAF // C99 300b57cec5SDimitry Andric FP_FAST_FMAL // C99 310b57cec5SDimitry Andric FP_ILOGB0 // C99 320b57cec5SDimitry Andric FP_ILOGBNAN // C99 330b57cec5SDimitry Andric MATH_ERRNO // C99 340b57cec5SDimitry Andric MATH_ERREXCEPT // C99 350b57cec5SDimitry Andric math_errhandling // C99 360b57cec5SDimitry Andric 370b57cec5SDimitry Andricnamespace std 380b57cec5SDimitry Andric{ 390b57cec5SDimitry Andric 400b57cec5SDimitry AndricTypes: 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric float_t // C99 430b57cec5SDimitry Andric double_t // C99 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric// C90 460b57cec5SDimitry Andric 470b57cec5SDimitry Andricfloating_point abs(floating_point x); 480b57cec5SDimitry Andric 490b57cec5SDimitry Andricfloating_point acos (arithmetic x); 500b57cec5SDimitry Andricfloat acosf(float x); 510b57cec5SDimitry Andriclong double acosl(long double x); 520b57cec5SDimitry Andric 530b57cec5SDimitry Andricfloating_point asin (arithmetic x); 540b57cec5SDimitry Andricfloat asinf(float x); 550b57cec5SDimitry Andriclong double asinl(long double x); 560b57cec5SDimitry Andric 570b57cec5SDimitry Andricfloating_point atan (arithmetic x); 580b57cec5SDimitry Andricfloat atanf(float x); 590b57cec5SDimitry Andriclong double atanl(long double x); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andricfloating_point atan2 (arithmetic y, arithmetic x); 620b57cec5SDimitry Andricfloat atan2f(float y, float x); 630b57cec5SDimitry Andriclong double atan2l(long double y, long double x); 640b57cec5SDimitry Andric 650b57cec5SDimitry Andricfloating_point ceil (arithmetic x); 660b57cec5SDimitry Andricfloat ceilf(float x); 670b57cec5SDimitry Andriclong double ceill(long double x); 680b57cec5SDimitry Andric 690b57cec5SDimitry Andricfloating_point cos (arithmetic x); 700b57cec5SDimitry Andricfloat cosf(float x); 710b57cec5SDimitry Andriclong double cosl(long double x); 720b57cec5SDimitry Andric 730b57cec5SDimitry Andricfloating_point cosh (arithmetic x); 740b57cec5SDimitry Andricfloat coshf(float x); 750b57cec5SDimitry Andriclong double coshl(long double x); 760b57cec5SDimitry Andric 770b57cec5SDimitry Andricfloating_point exp (arithmetic x); 780b57cec5SDimitry Andricfloat expf(float x); 790b57cec5SDimitry Andriclong double expl(long double x); 800b57cec5SDimitry Andric 810b57cec5SDimitry Andricfloating_point fabs (arithmetic x); 820b57cec5SDimitry Andricfloat fabsf(float x); 830b57cec5SDimitry Andriclong double fabsl(long double x); 840b57cec5SDimitry Andric 850b57cec5SDimitry Andricfloating_point floor (arithmetic x); 860b57cec5SDimitry Andricfloat floorf(float x); 870b57cec5SDimitry Andriclong double floorl(long double x); 880b57cec5SDimitry Andric 890b57cec5SDimitry Andricfloating_point fmod (arithmetic x, arithmetic y); 900b57cec5SDimitry Andricfloat fmodf(float x, float y); 910b57cec5SDimitry Andriclong double fmodl(long double x, long double y); 920b57cec5SDimitry Andric 930b57cec5SDimitry Andricfloating_point frexp (arithmetic value, int* exp); 940b57cec5SDimitry Andricfloat frexpf(float value, int* exp); 950b57cec5SDimitry Andriclong double frexpl(long double value, int* exp); 960b57cec5SDimitry Andric 970b57cec5SDimitry Andricfloating_point ldexp (arithmetic value, int exp); 980b57cec5SDimitry Andricfloat ldexpf(float value, int exp); 990b57cec5SDimitry Andriclong double ldexpl(long double value, int exp); 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andricfloating_point log (arithmetic x); 1020b57cec5SDimitry Andricfloat logf(float x); 1030b57cec5SDimitry Andriclong double logl(long double x); 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andricfloating_point log10 (arithmetic x); 1060b57cec5SDimitry Andricfloat log10f(float x); 1070b57cec5SDimitry Andriclong double log10l(long double x); 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andricfloating_point modf (floating_point value, floating_point* iptr); 1100b57cec5SDimitry Andricfloat modff(float value, float* iptr); 1110b57cec5SDimitry Andriclong double modfl(long double value, long double* iptr); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andricfloating_point pow (arithmetic x, arithmetic y); 1140b57cec5SDimitry Andricfloat powf(float x, float y); 1150b57cec5SDimitry Andriclong double powl(long double x, long double y); 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andricfloating_point sin (arithmetic x); 1180b57cec5SDimitry Andricfloat sinf(float x); 1190b57cec5SDimitry Andriclong double sinl(long double x); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andricfloating_point sinh (arithmetic x); 1220b57cec5SDimitry Andricfloat sinhf(float x); 1230b57cec5SDimitry Andriclong double sinhl(long double x); 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andricfloating_point sqrt (arithmetic x); 1260b57cec5SDimitry Andricfloat sqrtf(float x); 1270b57cec5SDimitry Andriclong double sqrtl(long double x); 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andricfloating_point tan (arithmetic x); 1300b57cec5SDimitry Andricfloat tanf(float x); 1310b57cec5SDimitry Andriclong double tanl(long double x); 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andricfloating_point tanh (arithmetic x); 1340b57cec5SDimitry Andricfloat tanhf(float x); 1350b57cec5SDimitry Andriclong double tanhl(long double x); 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric// C99 1380b57cec5SDimitry Andric 1390b57cec5SDimitry Andricbool signbit(arithmetic x); 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andricint fpclassify(arithmetic x); 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andricbool isfinite(arithmetic x); 1440b57cec5SDimitry Andricbool isinf(arithmetic x); 1450b57cec5SDimitry Andricbool isnan(arithmetic x); 1460b57cec5SDimitry Andricbool isnormal(arithmetic x); 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andricbool isgreater(arithmetic x, arithmetic y); 1490b57cec5SDimitry Andricbool isgreaterequal(arithmetic x, arithmetic y); 1500b57cec5SDimitry Andricbool isless(arithmetic x, arithmetic y); 1510b57cec5SDimitry Andricbool islessequal(arithmetic x, arithmetic y); 1520b57cec5SDimitry Andricbool islessgreater(arithmetic x, arithmetic y); 1530b57cec5SDimitry Andricbool isunordered(arithmetic x, arithmetic y); 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andricfloating_point acosh (arithmetic x); 1560b57cec5SDimitry Andricfloat acoshf(float x); 1570b57cec5SDimitry Andriclong double acoshl(long double x); 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andricfloating_point asinh (arithmetic x); 1600b57cec5SDimitry Andricfloat asinhf(float x); 1610b57cec5SDimitry Andriclong double asinhl(long double x); 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andricfloating_point atanh (arithmetic x); 1640b57cec5SDimitry Andricfloat atanhf(float x); 1650b57cec5SDimitry Andriclong double atanhl(long double x); 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andricfloating_point cbrt (arithmetic x); 1680b57cec5SDimitry Andricfloat cbrtf(float x); 1690b57cec5SDimitry Andriclong double cbrtl(long double x); 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andricfloating_point copysign (arithmetic x, arithmetic y); 1720b57cec5SDimitry Andricfloat copysignf(float x, float y); 1730b57cec5SDimitry Andriclong double copysignl(long double x, long double y); 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andricfloating_point erf (arithmetic x); 1760b57cec5SDimitry Andricfloat erff(float x); 1770b57cec5SDimitry Andriclong double erfl(long double x); 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andricfloating_point erfc (arithmetic x); 1800b57cec5SDimitry Andricfloat erfcf(float x); 1810b57cec5SDimitry Andriclong double erfcl(long double x); 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andricfloating_point exp2 (arithmetic x); 1840b57cec5SDimitry Andricfloat exp2f(float x); 1850b57cec5SDimitry Andriclong double exp2l(long double x); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andricfloating_point expm1 (arithmetic x); 1880b57cec5SDimitry Andricfloat expm1f(float x); 1890b57cec5SDimitry Andriclong double expm1l(long double x); 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andricfloating_point fdim (arithmetic x, arithmetic y); 1920b57cec5SDimitry Andricfloat fdimf(float x, float y); 1930b57cec5SDimitry Andriclong double fdiml(long double x, long double y); 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andricfloating_point fma (arithmetic x, arithmetic y, arithmetic z); 1960b57cec5SDimitry Andricfloat fmaf(float x, float y, float z); 1970b57cec5SDimitry Andriclong double fmal(long double x, long double y, long double z); 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andricfloating_point fmax (arithmetic x, arithmetic y); 2000b57cec5SDimitry Andricfloat fmaxf(float x, float y); 2010b57cec5SDimitry Andriclong double fmaxl(long double x, long double y); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andricfloating_point fmin (arithmetic x, arithmetic y); 2040b57cec5SDimitry Andricfloat fminf(float x, float y); 2050b57cec5SDimitry Andriclong double fminl(long double x, long double y); 2060b57cec5SDimitry Andric 2070b57cec5SDimitry Andricfloating_point hypot (arithmetic x, arithmetic y); 2080b57cec5SDimitry Andricfloat hypotf(float x, float y); 2090b57cec5SDimitry Andriclong double hypotl(long double x, long double y); 2100b57cec5SDimitry Andric 2110b57cec5SDimitry Andricdouble hypot(double x, double y, double z); // C++17 2120b57cec5SDimitry Andricfloat hypot(float x, float y, float z); // C++17 2130b57cec5SDimitry Andriclong double hypot(long double x, long double y, long double z); // C++17 2140b57cec5SDimitry Andric 2150b57cec5SDimitry Andricint ilogb (arithmetic x); 2160b57cec5SDimitry Andricint ilogbf(float x); 2170b57cec5SDimitry Andricint ilogbl(long double x); 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andricfloating_point lgamma (arithmetic x); 2200b57cec5SDimitry Andricfloat lgammaf(float x); 2210b57cec5SDimitry Andriclong double lgammal(long double x); 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andriclong long llrint (arithmetic x); 2240b57cec5SDimitry Andriclong long llrintf(float x); 2250b57cec5SDimitry Andriclong long llrintl(long double x); 2260b57cec5SDimitry Andric 2270b57cec5SDimitry Andriclong long llround (arithmetic x); 2280b57cec5SDimitry Andriclong long llroundf(float x); 2290b57cec5SDimitry Andriclong long llroundl(long double x); 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andricfloating_point log1p (arithmetic x); 2320b57cec5SDimitry Andricfloat log1pf(float x); 2330b57cec5SDimitry Andriclong double log1pl(long double x); 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andricfloating_point log2 (arithmetic x); 2360b57cec5SDimitry Andricfloat log2f(float x); 2370b57cec5SDimitry Andriclong double log2l(long double x); 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andricfloating_point logb (arithmetic x); 2400b57cec5SDimitry Andricfloat logbf(float x); 2410b57cec5SDimitry Andriclong double logbl(long double x); 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andriclong lrint (arithmetic x); 2440b57cec5SDimitry Andriclong lrintf(float x); 2450b57cec5SDimitry Andriclong lrintl(long double x); 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andriclong lround (arithmetic x); 2480b57cec5SDimitry Andriclong lroundf(float x); 2490b57cec5SDimitry Andriclong lroundl(long double x); 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andricdouble nan (const char* str); 2520b57cec5SDimitry Andricfloat nanf(const char* str); 2530b57cec5SDimitry Andriclong double nanl(const char* str); 2540b57cec5SDimitry Andric 2550b57cec5SDimitry Andricfloating_point nearbyint (arithmetic x); 2560b57cec5SDimitry Andricfloat nearbyintf(float x); 2570b57cec5SDimitry Andriclong double nearbyintl(long double x); 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andricfloating_point nextafter (arithmetic x, arithmetic y); 2600b57cec5SDimitry Andricfloat nextafterf(float x, float y); 2610b57cec5SDimitry Andriclong double nextafterl(long double x, long double y); 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andricfloating_point nexttoward (arithmetic x, long double y); 2640b57cec5SDimitry Andricfloat nexttowardf(float x, long double y); 2650b57cec5SDimitry Andriclong double nexttowardl(long double x, long double y); 2660b57cec5SDimitry Andric 2670b57cec5SDimitry Andricfloating_point remainder (arithmetic x, arithmetic y); 2680b57cec5SDimitry Andricfloat remainderf(float x, float y); 2690b57cec5SDimitry Andriclong double remainderl(long double x, long double y); 2700b57cec5SDimitry Andric 2710b57cec5SDimitry Andricfloating_point remquo (arithmetic x, arithmetic y, int* pquo); 2720b57cec5SDimitry Andricfloat remquof(float x, float y, int* pquo); 2730b57cec5SDimitry Andriclong double remquol(long double x, long double y, int* pquo); 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andricfloating_point rint (arithmetic x); 2760b57cec5SDimitry Andricfloat rintf(float x); 2770b57cec5SDimitry Andriclong double rintl(long double x); 2780b57cec5SDimitry Andric 2790b57cec5SDimitry Andricfloating_point round (arithmetic x); 2800b57cec5SDimitry Andricfloat roundf(float x); 2810b57cec5SDimitry Andriclong double roundl(long double x); 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andricfloating_point scalbln (arithmetic x, long ex); 2840b57cec5SDimitry Andricfloat scalblnf(float x, long ex); 2850b57cec5SDimitry Andriclong double scalblnl(long double x, long ex); 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andricfloating_point scalbn (arithmetic x, int ex); 2880b57cec5SDimitry Andricfloat scalbnf(float x, int ex); 2890b57cec5SDimitry Andriclong double scalbnl(long double x, int ex); 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andricfloating_point tgamma (arithmetic x); 2920b57cec5SDimitry Andricfloat tgammaf(float x); 2930b57cec5SDimitry Andriclong double tgammal(long double x); 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andricfloating_point trunc (arithmetic x); 2960b57cec5SDimitry Andricfloat truncf(float x); 2970b57cec5SDimitry Andriclong double truncl(long double x); 2980b57cec5SDimitry Andric 299*5ffd83dbSDimitry Andricconstexpr float lerp(float a, float b, float t) noexcept; // C++20 300*5ffd83dbSDimitry Andricconstexpr double lerp(double a, double b, double t) noexcept; // C++20 301*5ffd83dbSDimitry Andricconstexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20 302*5ffd83dbSDimitry Andric 3030b57cec5SDimitry Andric} // std 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andric*/ 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric#include <__config> 3080b57cec5SDimitry Andric#include <math.h> 3090b57cec5SDimitry Andric#include <version> 3100b57cec5SDimitry Andric#include <type_traits> 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3130b57cec5SDimitry Andric#pragma GCC system_header 3140b57cec5SDimitry Andric#endif 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 3170b57cec5SDimitry Andric#include <__undef_macros> 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andricusing ::signbit; 3220b57cec5SDimitry Andricusing ::fpclassify; 3230b57cec5SDimitry Andricusing ::isfinite; 3240b57cec5SDimitry Andricusing ::isinf; 3250b57cec5SDimitry Andricusing ::isnan; 3260b57cec5SDimitry Andricusing ::isnormal; 3270b57cec5SDimitry Andricusing ::isgreater; 3280b57cec5SDimitry Andricusing ::isgreaterequal; 3290b57cec5SDimitry Andricusing ::isless; 3300b57cec5SDimitry Andricusing ::islessequal; 3310b57cec5SDimitry Andricusing ::islessgreater; 3320b57cec5SDimitry Andricusing ::isunordered; 3330b57cec5SDimitry Andricusing ::isunordered; 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andricusing ::float_t; 3360b57cec5SDimitry Andricusing ::double_t; 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric#ifndef _AIX 3390b57cec5SDimitry Andricusing ::abs; 3400b57cec5SDimitry Andric#endif 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andricusing ::acos; 3430b57cec5SDimitry Andricusing ::acosf; 3440b57cec5SDimitry Andricusing ::asin; 3450b57cec5SDimitry Andricusing ::asinf; 3460b57cec5SDimitry Andricusing ::atan; 3470b57cec5SDimitry Andricusing ::atanf; 3480b57cec5SDimitry Andricusing ::atan2; 3490b57cec5SDimitry Andricusing ::atan2f; 3500b57cec5SDimitry Andricusing ::ceil; 3510b57cec5SDimitry Andricusing ::ceilf; 3520b57cec5SDimitry Andricusing ::cos; 3530b57cec5SDimitry Andricusing ::cosf; 3540b57cec5SDimitry Andricusing ::cosh; 3550b57cec5SDimitry Andricusing ::coshf; 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andricusing ::exp; 3580b57cec5SDimitry Andricusing ::expf; 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andricusing ::fabs; 3610b57cec5SDimitry Andricusing ::fabsf; 3620b57cec5SDimitry Andricusing ::floor; 3630b57cec5SDimitry Andricusing ::floorf; 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andricusing ::fmod; 3660b57cec5SDimitry Andricusing ::fmodf; 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andricusing ::frexp; 3690b57cec5SDimitry Andricusing ::frexpf; 3700b57cec5SDimitry Andricusing ::ldexp; 3710b57cec5SDimitry Andricusing ::ldexpf; 3720b57cec5SDimitry Andric 3730b57cec5SDimitry Andricusing ::log; 3740b57cec5SDimitry Andricusing ::logf; 3750b57cec5SDimitry Andric 3760b57cec5SDimitry Andricusing ::log10; 3770b57cec5SDimitry Andricusing ::log10f; 3780b57cec5SDimitry Andricusing ::modf; 3790b57cec5SDimitry Andricusing ::modff; 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andricusing ::pow; 3820b57cec5SDimitry Andricusing ::powf; 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andricusing ::sin; 3850b57cec5SDimitry Andricusing ::sinf; 3860b57cec5SDimitry Andricusing ::sinh; 3870b57cec5SDimitry Andricusing ::sinhf; 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andricusing ::sqrt; 3900b57cec5SDimitry Andricusing ::sqrtf; 3910b57cec5SDimitry Andricusing ::tan; 3920b57cec5SDimitry Andricusing ::tanf; 3930b57cec5SDimitry Andric 3940b57cec5SDimitry Andricusing ::tanh; 3950b57cec5SDimitry Andricusing ::tanhf; 3960b57cec5SDimitry Andric 3970b57cec5SDimitry Andricusing ::acosh; 3980b57cec5SDimitry Andricusing ::acoshf; 3990b57cec5SDimitry Andricusing ::asinh; 4000b57cec5SDimitry Andricusing ::asinhf; 4010b57cec5SDimitry Andricusing ::atanh; 4020b57cec5SDimitry Andricusing ::atanhf; 4030b57cec5SDimitry Andricusing ::cbrt; 4040b57cec5SDimitry Andricusing ::cbrtf; 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andricusing ::copysign; 4070b57cec5SDimitry Andricusing ::copysignf; 4080b57cec5SDimitry Andric 4090b57cec5SDimitry Andricusing ::erf; 4100b57cec5SDimitry Andricusing ::erff; 4110b57cec5SDimitry Andricusing ::erfc; 4120b57cec5SDimitry Andricusing ::erfcf; 4130b57cec5SDimitry Andricusing ::exp2; 4140b57cec5SDimitry Andricusing ::exp2f; 4150b57cec5SDimitry Andricusing ::expm1; 4160b57cec5SDimitry Andricusing ::expm1f; 4170b57cec5SDimitry Andricusing ::fdim; 4180b57cec5SDimitry Andricusing ::fdimf; 4190b57cec5SDimitry Andricusing ::fmaf; 4200b57cec5SDimitry Andricusing ::fma; 4210b57cec5SDimitry Andricusing ::fmax; 4220b57cec5SDimitry Andricusing ::fmaxf; 4230b57cec5SDimitry Andricusing ::fmin; 4240b57cec5SDimitry Andricusing ::fminf; 4250b57cec5SDimitry Andricusing ::hypot; 4260b57cec5SDimitry Andricusing ::hypotf; 4270b57cec5SDimitry Andricusing ::ilogb; 4280b57cec5SDimitry Andricusing ::ilogbf; 4290b57cec5SDimitry Andricusing ::lgamma; 4300b57cec5SDimitry Andricusing ::lgammaf; 4310b57cec5SDimitry Andricusing ::llrint; 4320b57cec5SDimitry Andricusing ::llrintf; 4330b57cec5SDimitry Andricusing ::llround; 4340b57cec5SDimitry Andricusing ::llroundf; 4350b57cec5SDimitry Andricusing ::log1p; 4360b57cec5SDimitry Andricusing ::log1pf; 4370b57cec5SDimitry Andricusing ::log2; 4380b57cec5SDimitry Andricusing ::log2f; 4390b57cec5SDimitry Andricusing ::logb; 4400b57cec5SDimitry Andricusing ::logbf; 4410b57cec5SDimitry Andricusing ::lrint; 4420b57cec5SDimitry Andricusing ::lrintf; 4430b57cec5SDimitry Andricusing ::lround; 4440b57cec5SDimitry Andricusing ::lroundf; 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andricusing ::nan; 4470b57cec5SDimitry Andricusing ::nanf; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andricusing ::nearbyint; 4500b57cec5SDimitry Andricusing ::nearbyintf; 4510b57cec5SDimitry Andricusing ::nextafter; 4520b57cec5SDimitry Andricusing ::nextafterf; 4530b57cec5SDimitry Andricusing ::nexttoward; 4540b57cec5SDimitry Andricusing ::nexttowardf; 4550b57cec5SDimitry Andricusing ::remainder; 4560b57cec5SDimitry Andricusing ::remainderf; 4570b57cec5SDimitry Andricusing ::remquo; 4580b57cec5SDimitry Andricusing ::remquof; 4590b57cec5SDimitry Andricusing ::rint; 4600b57cec5SDimitry Andricusing ::rintf; 4610b57cec5SDimitry Andricusing ::round; 4620b57cec5SDimitry Andricusing ::roundf; 4630b57cec5SDimitry Andricusing ::scalbln; 4640b57cec5SDimitry Andricusing ::scalblnf; 4650b57cec5SDimitry Andricusing ::scalbn; 4660b57cec5SDimitry Andricusing ::scalbnf; 4670b57cec5SDimitry Andricusing ::tgamma; 4680b57cec5SDimitry Andricusing ::tgammaf; 4690b57cec5SDimitry Andricusing ::trunc; 4700b57cec5SDimitry Andricusing ::truncf; 4710b57cec5SDimitry Andric 4720b57cec5SDimitry Andricusing ::acosl; 4730b57cec5SDimitry Andricusing ::asinl; 4740b57cec5SDimitry Andricusing ::atanl; 4750b57cec5SDimitry Andricusing ::atan2l; 4760b57cec5SDimitry Andricusing ::ceill; 4770b57cec5SDimitry Andricusing ::cosl; 4780b57cec5SDimitry Andricusing ::coshl; 4790b57cec5SDimitry Andricusing ::expl; 4800b57cec5SDimitry Andricusing ::fabsl; 4810b57cec5SDimitry Andricusing ::floorl; 4820b57cec5SDimitry Andricusing ::fmodl; 4830b57cec5SDimitry Andricusing ::frexpl; 4840b57cec5SDimitry Andricusing ::ldexpl; 4850b57cec5SDimitry Andricusing ::logl; 4860b57cec5SDimitry Andricusing ::log10l; 4870b57cec5SDimitry Andricusing ::modfl; 4880b57cec5SDimitry Andricusing ::powl; 4890b57cec5SDimitry Andricusing ::sinl; 4900b57cec5SDimitry Andricusing ::sinhl; 4910b57cec5SDimitry Andricusing ::sqrtl; 4920b57cec5SDimitry Andricusing ::tanl; 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andricusing ::tanhl; 4950b57cec5SDimitry Andricusing ::acoshl; 4960b57cec5SDimitry Andricusing ::asinhl; 4970b57cec5SDimitry Andricusing ::atanhl; 4980b57cec5SDimitry Andricusing ::cbrtl; 4990b57cec5SDimitry Andric 5000b57cec5SDimitry Andricusing ::copysignl; 5010b57cec5SDimitry Andric 5020b57cec5SDimitry Andricusing ::erfl; 5030b57cec5SDimitry Andricusing ::erfcl; 5040b57cec5SDimitry Andricusing ::exp2l; 5050b57cec5SDimitry Andricusing ::expm1l; 5060b57cec5SDimitry Andricusing ::fdiml; 5070b57cec5SDimitry Andricusing ::fmal; 5080b57cec5SDimitry Andricusing ::fmaxl; 5090b57cec5SDimitry Andricusing ::fminl; 5100b57cec5SDimitry Andricusing ::hypotl; 5110b57cec5SDimitry Andricusing ::ilogbl; 5120b57cec5SDimitry Andricusing ::lgammal; 5130b57cec5SDimitry Andricusing ::llrintl; 5140b57cec5SDimitry Andricusing ::llroundl; 5150b57cec5SDimitry Andricusing ::log1pl; 5160b57cec5SDimitry Andricusing ::log2l; 5170b57cec5SDimitry Andricusing ::logbl; 5180b57cec5SDimitry Andricusing ::lrintl; 5190b57cec5SDimitry Andricusing ::lroundl; 5200b57cec5SDimitry Andricusing ::nanl; 5210b57cec5SDimitry Andricusing ::nearbyintl; 5220b57cec5SDimitry Andricusing ::nextafterl; 5230b57cec5SDimitry Andricusing ::nexttowardl; 5240b57cec5SDimitry Andricusing ::remainderl; 5250b57cec5SDimitry Andricusing ::remquol; 5260b57cec5SDimitry Andricusing ::rintl; 5270b57cec5SDimitry Andricusing ::roundl; 5280b57cec5SDimitry Andricusing ::scalblnl; 5290b57cec5SDimitry Andricusing ::scalbnl; 5300b57cec5SDimitry Andricusing ::tgammal; 5310b57cec5SDimitry Andricusing ::truncl; 5320b57cec5SDimitry Andric 5330b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 5340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); } 5350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); } 5360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); } 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andrictemplate <class _A1, class _A2, class _A3> 5390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 5400b57cec5SDimitry Andrictypename _EnableIf 5410b57cec5SDimitry Andric< 5420b57cec5SDimitry Andric is_arithmetic<_A1>::value && 5430b57cec5SDimitry Andric is_arithmetic<_A2>::value && 5440b57cec5SDimitry Andric is_arithmetic<_A3>::value, 5450b57cec5SDimitry Andric __promote<_A1, _A2, _A3> 5460b57cec5SDimitry Andric>::type 5470b57cec5SDimitry Andrichypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT 5480b57cec5SDimitry Andric{ 5490b57cec5SDimitry Andric typedef typename __promote<_A1, _A2, _A3>::type __result_type; 5500b57cec5SDimitry Andric static_assert((!(is_same<_A1, __result_type>::value && 5510b57cec5SDimitry Andric is_same<_A2, __result_type>::value && 5520b57cec5SDimitry Andric is_same<_A3, __result_type>::value)), ""); 5530b57cec5SDimitry Andric return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); 5540b57cec5SDimitry Andric} 5550b57cec5SDimitry Andric#endif 5560b57cec5SDimitry Andric 5570b57cec5SDimitry Andrictemplate <class _A1> 5580b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 5590b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 5600b57cec5SDimitry Andric__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT 5610b57cec5SDimitry Andric{ 5620b57cec5SDimitry Andric#if __has_builtin(__builtin_isnan) 5630b57cec5SDimitry Andric return __builtin_isnan(__lcpp_x); 5640b57cec5SDimitry Andric#else 5650b57cec5SDimitry Andric return isnan(__lcpp_x); 5660b57cec5SDimitry Andric#endif 5670b57cec5SDimitry Andric} 5680b57cec5SDimitry Andric 5690b57cec5SDimitry Andrictemplate <class _A1> 5700b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 5710b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 5720b57cec5SDimitry Andric__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT 5730b57cec5SDimitry Andric{ 5740b57cec5SDimitry Andric return isnan(__lcpp_x); 5750b57cec5SDimitry Andric} 5760b57cec5SDimitry Andric 5770b57cec5SDimitry Andrictemplate <class _A1> 5780b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 5790b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 5800b57cec5SDimitry Andric__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT 5810b57cec5SDimitry Andric{ 5820b57cec5SDimitry Andric#if __has_builtin(__builtin_isinf) 5830b57cec5SDimitry Andric return __builtin_isinf(__lcpp_x); 5840b57cec5SDimitry Andric#else 5850b57cec5SDimitry Andric return isinf(__lcpp_x); 5860b57cec5SDimitry Andric#endif 5870b57cec5SDimitry Andric} 5880b57cec5SDimitry Andric 5890b57cec5SDimitry Andrictemplate <class _A1> 5900b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 5910b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 5920b57cec5SDimitry Andric__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT 5930b57cec5SDimitry Andric{ 5940b57cec5SDimitry Andric return isinf(__lcpp_x); 5950b57cec5SDimitry Andric} 5960b57cec5SDimitry Andric 5970b57cec5SDimitry Andrictemplate <class _A1> 5980b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 5990b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type 6000b57cec5SDimitry Andric__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT 6010b57cec5SDimitry Andric{ 6020b57cec5SDimitry Andric#if __has_builtin(__builtin_isfinite) 6030b57cec5SDimitry Andric return __builtin_isfinite(__lcpp_x); 6040b57cec5SDimitry Andric#else 6050b57cec5SDimitry Andric return isfinite(__lcpp_x); 6060b57cec5SDimitry Andric#endif 6070b57cec5SDimitry Andric} 6080b57cec5SDimitry Andric 6090b57cec5SDimitry Andrictemplate <class _A1> 6100b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 6110b57cec5SDimitry Andric_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type 6120b57cec5SDimitry Andric__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT 6130b57cec5SDimitry Andric{ 6140b57cec5SDimitry Andric return isfinite(__lcpp_x); 6150b57cec5SDimitry Andric} 6160b57cec5SDimitry Andric 6170b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 6180b57cec5SDimitry Andrictemplate <typename _Fp> 6190b57cec5SDimitry Andricconstexpr 6200b57cec5SDimitry Andric_Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept { 6210b57cec5SDimitry Andric if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0)) 6220b57cec5SDimitry Andric return __t * __b + (1 - __t) * __a; 6230b57cec5SDimitry Andric 6240b57cec5SDimitry Andric if (__t == 1) return __b; 6250b57cec5SDimitry Andric const _Fp __x = __a + __t * (__b - __a); 6260b57cec5SDimitry Andric if (__t > 1 == __b > __a) 6270b57cec5SDimitry Andric return __b < __x ? __x : __b; 6280b57cec5SDimitry Andric else 6290b57cec5SDimitry Andric return __x < __b ? __x : __b; 6300b57cec5SDimitry Andric} 6310b57cec5SDimitry Andric 6320b57cec5SDimitry Andricconstexpr float 6330b57cec5SDimitry Andriclerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); } 6340b57cec5SDimitry Andric 6350b57cec5SDimitry Andricconstexpr double 6360b57cec5SDimitry Andriclerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } 6370b57cec5SDimitry Andric 6380b57cec5SDimitry Andricconstexpr long double 6390b57cec5SDimitry Andriclerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } 6400b57cec5SDimitry Andric 6410b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andrictemplate <class _IntT, class _FloatT, 6440b57cec5SDimitry Andric bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits), 6450b57cec5SDimitry Andric int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> 6460b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 6470b57cec5SDimitry Andric_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT { 6480b57cec5SDimitry Andric static_assert(is_floating_point<_FloatT>::value, "must be a floating point type"); 6490b57cec5SDimitry Andric static_assert(is_integral<_IntT>::value, "must be an integral type"); 6500b57cec5SDimitry Andric static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); 6510b57cec5SDimitry Andric static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value 6520b57cec5SDimitry Andric || _IsSame<_FloatT,long double>::value), "unsupported floating point type"); 6530b57cec5SDimitry Andric return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits); 6540b57cec5SDimitry Andric} 6550b57cec5SDimitry Andric 6560b57cec5SDimitry Andric// Convert a floating point number to the specified integral type after 6570b57cec5SDimitry Andric// clamping to the integral types representable range. 6580b57cec5SDimitry Andric// 6590b57cec5SDimitry Andric// The behavior is undefined if `__r` is NaN. 6600b57cec5SDimitry Andrictemplate <class _IntT, class _RealT> 6610b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 6620b57cec5SDimitry Andric_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT { 6630b57cec5SDimitry Andric using _Lim = std::numeric_limits<_IntT>; 6640b57cec5SDimitry Andric const _IntT _MaxVal = std::__max_representable_int_for_float<_IntT, _RealT>(); 6650b57cec5SDimitry Andric if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) { 6660b57cec5SDimitry Andric return _Lim::max(); 6670b57cec5SDimitry Andric } else if (__r <= _Lim::lowest()) { 6680b57cec5SDimitry Andric return _Lim::min(); 6690b57cec5SDimitry Andric } 6700b57cec5SDimitry Andric return static_cast<_IntT>(__r); 6710b57cec5SDimitry Andric} 6720b57cec5SDimitry Andric 6730b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andric_LIBCPP_POP_MACROS 6760b57cec5SDimitry Andric 6770b57cec5SDimitry Andric#endif // _LIBCPP_CMATH 678