chromium/third_party/libc++/src/include/cmath

// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_CMATH
#define _LIBCPP_CMATH

/*
    cmath synopsis

Macros:

    HUGE_VAL
    HUGE_VALF               // C99
    HUGE_VALL               // C99
    INFINITY                // C99
    NAN                     // C99
    FP_INFINITE             // C99
    FP_NAN                  // C99
    FP_NORMAL               // C99
    FP_SUBNORMAL            // C99
    FP_ZERO                 // C99
    FP_FAST_FMA             // C99
    FP_FAST_FMAF            // C99
    FP_FAST_FMAL            // C99
    FP_ILOGB0               // C99
    FP_ILOGBNAN             // C99
    MATH_ERRNO              // C99
    MATH_ERREXCEPT          // C99
    math_errhandling        // C99

namespace std
{

Types:

    float_t                 // C99
    double_t                // C99

// C90

floating_point abs(floating_point x);

floating_point acos (arithmetic x);
float          acosf(float x);
long double    acosl(long double x);

floating_point asin (arithmetic x);
float          asinf(float x);
long double    asinl(long double x);

floating_point atan (arithmetic x);
float          atanf(float x);
long double    atanl(long double x);

floating_point atan2 (arithmetic y, arithmetic x);
float          atan2f(float y, float x);
long double    atan2l(long double y, long double x);

floating_point ceil (arithmetic x);
float          ceilf(float x);
long double    ceill(long double x);

floating_point cos (arithmetic x);
float          cosf(float x);
long double    cosl(long double x);

floating_point cosh (arithmetic x);
float          coshf(float x);
long double    coshl(long double x);

floating_point exp (arithmetic x);
float          expf(float x);
long double    expl(long double x);

floating_point fabs (arithmetic x);
float          fabsf(float x);
long double    fabsl(long double x);

floating_point floor (arithmetic x);
float          floorf(float x);
long double    floorl(long double x);

floating_point fmod (arithmetic x, arithmetic y);
float          fmodf(float x, float y);
long double    fmodl(long double x, long double y);

floating_point frexp (arithmetic value, int* exp);
float          frexpf(float value, int* exp);
long double    frexpl(long double value, int* exp);

floating_point ldexp (arithmetic value, int exp);
float          ldexpf(float value, int exp);
long double    ldexpl(long double value, int exp);

floating_point log (arithmetic x);
float          logf(float x);
long double    logl(long double x);

floating_point log10 (arithmetic x);
float          log10f(float x);
long double    log10l(long double x);

floating_point modf (floating_point value, floating_point* iptr);
float          modff(float value, float* iptr);
long double    modfl(long double value, long double* iptr);

floating_point pow (arithmetic x, arithmetic y);
float          powf(float x, float y);
long double    powl(long double x, long double y);

floating_point sin (arithmetic x);
float          sinf(float x);
long double    sinl(long double x);

floating_point sinh (arithmetic x);
float          sinhf(float x);
long double    sinhl(long double x);

floating_point sqrt (arithmetic x);
float          sqrtf(float x);
long double    sqrtl(long double x);

floating_point tan (arithmetic x);
float          tanf(float x);
long double    tanl(long double x);

floating_point tanh (arithmetic x);
float          tanhf(float x);
long double    tanhl(long double x);

//  C99

bool signbit(arithmetic x);

int fpclassify(arithmetic x);

bool isfinite(arithmetic x);
bool isinf(arithmetic x);
bool isnan(arithmetic x);
bool isnormal(arithmetic x);

bool isgreater(arithmetic x, arithmetic y);
bool isgreaterequal(arithmetic x, arithmetic y);
bool isless(arithmetic x, arithmetic y);
bool islessequal(arithmetic x, arithmetic y);
bool islessgreater(arithmetic x, arithmetic y);
bool isunordered(arithmetic x, arithmetic y);

floating_point acosh (arithmetic x);
float          acoshf(float x);
long double    acoshl(long double x);

floating_point asinh (arithmetic x);
float          asinhf(float x);
long double    asinhl(long double x);

floating_point atanh (arithmetic x);
float          atanhf(float x);
long double    atanhl(long double x);

floating_point cbrt (arithmetic x);
float          cbrtf(float x);
long double    cbrtl(long double x);

floating_point copysign (arithmetic x, arithmetic y);
float          copysignf(float x, float y);
long double    copysignl(long double x, long double y);

floating_point erf (arithmetic x);
float          erff(float x);
long double    erfl(long double x);

floating_point erfc (arithmetic x);
float          erfcf(float x);
long double    erfcl(long double x);

floating_point exp2 (arithmetic x);
float          exp2f(float x);
long double    exp2l(long double x);

floating_point expm1 (arithmetic x);
float          expm1f(float x);
long double    expm1l(long double x);

floating_point fdim (arithmetic x, arithmetic y);
float          fdimf(float x, float y);
long double    fdiml(long double x, long double y);

floating_point fma (arithmetic x, arithmetic y, arithmetic z);
float          fmaf(float x, float y, float z);
long double    fmal(long double x, long double y, long double z);

floating_point fmax (arithmetic x, arithmetic y);
float          fmaxf(float x, float y);
long double    fmaxl(long double x, long double y);

floating_point fmin (arithmetic x, arithmetic y);
float          fminf(float x, float y);
long double    fminl(long double x, long double y);

double         hermite(unsigned n, double x);                    // C++17
float          hermite(unsigned n, float x);                     // C++17
long double    hermite(unsigned n, long double x);               // C++17
float          hermitef(unsigned n, float x);                    // C++17
long double    hermitel(unsigned n, long double x);              // C++17
template <class Integer>
double         hermite(unsigned n, Integer x);                   // C++17

floating_point hypot (arithmetic x, arithmetic y);
float          hypotf(float x, float y);
long double    hypotl(long double x, long double y);

double       hypot(double x, double y, double z);                // C++17
float        hypot(float x, float y, float z);                   // C++17
long double  hypot(long double x, long double y, long double z); // C++17

int ilogb (arithmetic x);
int ilogbf(float x);
int ilogbl(long double x);

floating_point lgamma (arithmetic x);
float          lgammaf(float x);
long double    lgammal(long double x);

long long llrint (arithmetic x);
long long llrintf(float x);
long long llrintl(long double x);

long long llround (arithmetic x);
long long llroundf(float x);
long long llroundl(long double x);

floating_point log1p (arithmetic x);
float          log1pf(float x);
long double    log1pl(long double x);

floating_point log2 (arithmetic x);
float          log2f(float x);
long double    log2l(long double x);

floating_point logb (arithmetic x);
float          logbf(float x);
long double    logbl(long double x);

long lrint (arithmetic x);
long lrintf(float x);
long lrintl(long double x);

long lround (arithmetic x);
long lroundf(float x);
long lroundl(long double x);

double      nan (const char* str);
float       nanf(const char* str);
long double nanl(const char* str);

floating_point nearbyint (arithmetic x);
float          nearbyintf(float x);
long double    nearbyintl(long double x);

floating_point nextafter (arithmetic x, arithmetic y);
float          nextafterf(float x, float y);
long double    nextafterl(long double x, long double y);

floating_point nexttoward (arithmetic x, long double y);
float          nexttowardf(float x, long double y);
long double    nexttowardl(long double x, long double y);

floating_point remainder (arithmetic x, arithmetic y);
float          remainderf(float x, float y);
long double    remainderl(long double x, long double y);

floating_point remquo (arithmetic x, arithmetic y, int* pquo);
float          remquof(float x, float y, int* pquo);
long double    remquol(long double x, long double y, int* pquo);

floating_point rint (arithmetic x);
float          rintf(float x);
long double    rintl(long double x);

floating_point round (arithmetic x);
float          roundf(float x);
long double    roundl(long double x);

floating_point scalbln (arithmetic x, long ex);
float          scalblnf(float x, long ex);
long double    scalblnl(long double x, long ex);

floating_point scalbn (arithmetic x, int ex);
float          scalbnf(float x, int ex);
long double    scalbnl(long double x, int ex);

floating_point tgamma (arithmetic x);
float          tgammaf(float x);
long double    tgammal(long double x);

floating_point trunc (arithmetic x);
float          truncf(float x);
long double    truncl(long double x);

constexpr float       lerp(float a, float b, float t) noexcept;                   // C++20
constexpr double      lerp(double a, double b, double t) noexcept;                // C++20
constexpr long double lerp(long double a, long double b, long double t) noexcept; // C++20

}  // std

*/

#include <__config>
#include <__math/hypot.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_arithmetic.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_floating_point.h>
#include <__type_traits/is_same.h>
#include <__type_traits/promote.h>
#include <__type_traits/remove_cv.h>
#include <limits>
#include <version>

#include <__math/special_functions.h>
#include <math.h>

#ifndef _LIBCPP_MATH_H
#   error <cmath> tried including <math.h> but didn't find libc++'s <math.h> header. \
          This usually means that your header search paths are not configured properly. \
          The header search paths should contain the C++ Standard Library headers before \
          any C Standard Library, and you are probably using compiler flags that make that \
          not be the case.
#endif

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#  pragma GCC system_header
#endif

_LIBCPP_PUSH_MACROS
#include <__undef_macros>

_LIBCPP_BEGIN_NAMESPACE_STD

signbit _LIBCPP_USING_IF_EXISTS;
fpclassify _LIBCPP_USING_IF_EXISTS;
isfinite _LIBCPP_USING_IF_EXISTS;
isinf _LIBCPP_USING_IF_EXISTS;
isnan _LIBCPP_USING_IF_EXISTS;
isnormal _LIBCPP_USING_IF_EXISTS;
isgreater _LIBCPP_USING_IF_EXISTS;
isgreaterequal _LIBCPP_USING_IF_EXISTS;
isless _LIBCPP_USING_IF_EXISTS;
islessequal _LIBCPP_USING_IF_EXISTS;
islessgreater _LIBCPP_USING_IF_EXISTS;
isunordered _LIBCPP_USING_IF_EXISTS;
isunordered _LIBCPP_USING_IF_EXISTS;

float_t _LIBCPP_USING_IF_EXISTS;
double_t _LIBCPP_USING_IF_EXISTS;

abs _LIBCPP_USING_IF_EXISTS;

acos _LIBCPP_USING_IF_EXISTS;
acosf _LIBCPP_USING_IF_EXISTS;
asin _LIBCPP_USING_IF_EXISTS;
asinf _LIBCPP_USING_IF_EXISTS;
atan _LIBCPP_USING_IF_EXISTS;
atanf _LIBCPP_USING_IF_EXISTS;
atan2 _LIBCPP_USING_IF_EXISTS;
atan2f _LIBCPP_USING_IF_EXISTS;
ceil _LIBCPP_USING_IF_EXISTS;
ceilf _LIBCPP_USING_IF_EXISTS;
cos _LIBCPP_USING_IF_EXISTS;
cosf _LIBCPP_USING_IF_EXISTS;
cosh _LIBCPP_USING_IF_EXISTS;
coshf _LIBCPP_USING_IF_EXISTS;

exp _LIBCPP_USING_IF_EXISTS;
expf _LIBCPP_USING_IF_EXISTS;

fabs _LIBCPP_USING_IF_EXISTS;
fabsf _LIBCPP_USING_IF_EXISTS;
floor _LIBCPP_USING_IF_EXISTS;
floorf _LIBCPP_USING_IF_EXISTS;

fmod _LIBCPP_USING_IF_EXISTS;
fmodf _LIBCPP_USING_IF_EXISTS;

frexp _LIBCPP_USING_IF_EXISTS;
frexpf _LIBCPP_USING_IF_EXISTS;
ldexp _LIBCPP_USING_IF_EXISTS;
ldexpf _LIBCPP_USING_IF_EXISTS;

log _LIBCPP_USING_IF_EXISTS;
logf _LIBCPP_USING_IF_EXISTS;

log10 _LIBCPP_USING_IF_EXISTS;
log10f _LIBCPP_USING_IF_EXISTS;
modf _LIBCPP_USING_IF_EXISTS;
modff _LIBCPP_USING_IF_EXISTS;

pow _LIBCPP_USING_IF_EXISTS;
powf _LIBCPP_USING_IF_EXISTS;

sin _LIBCPP_USING_IF_EXISTS;
sinf _LIBCPP_USING_IF_EXISTS;
sinh _LIBCPP_USING_IF_EXISTS;
sinhf _LIBCPP_USING_IF_EXISTS;

sqrt _LIBCPP_USING_IF_EXISTS;
sqrtf _LIBCPP_USING_IF_EXISTS;
tan _LIBCPP_USING_IF_EXISTS;
tanf _LIBCPP_USING_IF_EXISTS;

tanh _LIBCPP_USING_IF_EXISTS;
tanhf _LIBCPP_USING_IF_EXISTS;

acosh _LIBCPP_USING_IF_EXISTS;
acoshf _LIBCPP_USING_IF_EXISTS;
asinh _LIBCPP_USING_IF_EXISTS;
asinhf _LIBCPP_USING_IF_EXISTS;
atanh _LIBCPP_USING_IF_EXISTS;
atanhf _LIBCPP_USING_IF_EXISTS;
cbrt _LIBCPP_USING_IF_EXISTS;
cbrtf _LIBCPP_USING_IF_EXISTS;

copysign _LIBCPP_USING_IF_EXISTS;
copysignf _LIBCPP_USING_IF_EXISTS;

erf _LIBCPP_USING_IF_EXISTS;
erff _LIBCPP_USING_IF_EXISTS;
erfc _LIBCPP_USING_IF_EXISTS;
erfcf _LIBCPP_USING_IF_EXISTS;
exp2 _LIBCPP_USING_IF_EXISTS;
exp2f _LIBCPP_USING_IF_EXISTS;
expm1 _LIBCPP_USING_IF_EXISTS;
expm1f _LIBCPP_USING_IF_EXISTS;
fdim _LIBCPP_USING_IF_EXISTS;
fdimf _LIBCPP_USING_IF_EXISTS;
fmaf _LIBCPP_USING_IF_EXISTS;
fma _LIBCPP_USING_IF_EXISTS;
fmax _LIBCPP_USING_IF_EXISTS;
fmaxf _LIBCPP_USING_IF_EXISTS;
fmin _LIBCPP_USING_IF_EXISTS;
fminf _LIBCPP_USING_IF_EXISTS;
hypot _LIBCPP_USING_IF_EXISTS;
hypotf _LIBCPP_USING_IF_EXISTS;
ilogb _LIBCPP_USING_IF_EXISTS;
ilogbf _LIBCPP_USING_IF_EXISTS;
lgamma _LIBCPP_USING_IF_EXISTS;
lgammaf _LIBCPP_USING_IF_EXISTS;
llrint _LIBCPP_USING_IF_EXISTS;
llrintf _LIBCPP_USING_IF_EXISTS;
llround _LIBCPP_USING_IF_EXISTS;
llroundf _LIBCPP_USING_IF_EXISTS;
log1p _LIBCPP_USING_IF_EXISTS;
log1pf _LIBCPP_USING_IF_EXISTS;
log2 _LIBCPP_USING_IF_EXISTS;
log2f _LIBCPP_USING_IF_EXISTS;
logb _LIBCPP_USING_IF_EXISTS;
logbf _LIBCPP_USING_IF_EXISTS;
lrint _LIBCPP_USING_IF_EXISTS;
lrintf _LIBCPP_USING_IF_EXISTS;
lround _LIBCPP_USING_IF_EXISTS;
lroundf _LIBCPP_USING_IF_EXISTS;

nan _LIBCPP_USING_IF_EXISTS;
nanf _LIBCPP_USING_IF_EXISTS;

nearbyint _LIBCPP_USING_IF_EXISTS;
nearbyintf _LIBCPP_USING_IF_EXISTS;
nextafter _LIBCPP_USING_IF_EXISTS;
nextafterf _LIBCPP_USING_IF_EXISTS;
nexttoward _LIBCPP_USING_IF_EXISTS;
nexttowardf _LIBCPP_USING_IF_EXISTS;
remainder _LIBCPP_USING_IF_EXISTS;
remainderf _LIBCPP_USING_IF_EXISTS;
remquo _LIBCPP_USING_IF_EXISTS;
remquof _LIBCPP_USING_IF_EXISTS;
rint _LIBCPP_USING_IF_EXISTS;
rintf _LIBCPP_USING_IF_EXISTS;
round _LIBCPP_USING_IF_EXISTS;
roundf _LIBCPP_USING_IF_EXISTS;
scalbln _LIBCPP_USING_IF_EXISTS;
scalblnf _LIBCPP_USING_IF_EXISTS;
scalbn _LIBCPP_USING_IF_EXISTS;
scalbnf _LIBCPP_USING_IF_EXISTS;
tgamma _LIBCPP_USING_IF_EXISTS;
tgammaf _LIBCPP_USING_IF_EXISTS;
trunc _LIBCPP_USING_IF_EXISTS;
truncf _LIBCPP_USING_IF_EXISTS;

acosl _LIBCPP_USING_IF_EXISTS;
asinl _LIBCPP_USING_IF_EXISTS;
atanl _LIBCPP_USING_IF_EXISTS;
atan2l _LIBCPP_USING_IF_EXISTS;
ceill _LIBCPP_USING_IF_EXISTS;
cosl _LIBCPP_USING_IF_EXISTS;
coshl _LIBCPP_USING_IF_EXISTS;
expl _LIBCPP_USING_IF_EXISTS;
fabsl _LIBCPP_USING_IF_EXISTS;
floorl _LIBCPP_USING_IF_EXISTS;
fmodl _LIBCPP_USING_IF_EXISTS;
frexpl _LIBCPP_USING_IF_EXISTS;
ldexpl _LIBCPP_USING_IF_EXISTS;
logl _LIBCPP_USING_IF_EXISTS;
log10l _LIBCPP_USING_IF_EXISTS;
modfl _LIBCPP_USING_IF_EXISTS;
powl _LIBCPP_USING_IF_EXISTS;
sinl _LIBCPP_USING_IF_EXISTS;
sinhl _LIBCPP_USING_IF_EXISTS;
sqrtl _LIBCPP_USING_IF_EXISTS;
tanl _LIBCPP_USING_IF_EXISTS;

tanhl _LIBCPP_USING_IF_EXISTS;
acoshl _LIBCPP_USING_IF_EXISTS;
asinhl _LIBCPP_USING_IF_EXISTS;
atanhl _LIBCPP_USING_IF_EXISTS;
cbrtl _LIBCPP_USING_IF_EXISTS;

copysignl _LIBCPP_USING_IF_EXISTS;

erfl _LIBCPP_USING_IF_EXISTS;
erfcl _LIBCPP_USING_IF_EXISTS;
exp2l _LIBCPP_USING_IF_EXISTS;
expm1l _LIBCPP_USING_IF_EXISTS;
fdiml _LIBCPP_USING_IF_EXISTS;
fmal _LIBCPP_USING_IF_EXISTS;
fmaxl _LIBCPP_USING_IF_EXISTS;
fminl _LIBCPP_USING_IF_EXISTS;
hypotl _LIBCPP_USING_IF_EXISTS;
ilogbl _LIBCPP_USING_IF_EXISTS;
lgammal _LIBCPP_USING_IF_EXISTS;
llrintl _LIBCPP_USING_IF_EXISTS;
llroundl _LIBCPP_USING_IF_EXISTS;
log1pl _LIBCPP_USING_IF_EXISTS;
log2l _LIBCPP_USING_IF_EXISTS;
logbl _LIBCPP_USING_IF_EXISTS;
lrintl _LIBCPP_USING_IF_EXISTS;
lroundl _LIBCPP_USING_IF_EXISTS;
nanl _LIBCPP_USING_IF_EXISTS;
nearbyintl _LIBCPP_USING_IF_EXISTS;
nextafterl _LIBCPP_USING_IF_EXISTS;
nexttowardl _LIBCPP_USING_IF_EXISTS;
remainderl _LIBCPP_USING_IF_EXISTS;
remquol _LIBCPP_USING_IF_EXISTS;
rintl _LIBCPP_USING_IF_EXISTS;
roundl _LIBCPP_USING_IF_EXISTS;
scalblnl _LIBCPP_USING_IF_EXISTS;
scalbnl _LIBCPP_USING_IF_EXISTS;
tgammal _LIBCPP_USING_IF_EXISTS;
truncl _LIBCPP_USING_IF_EXISTS;

template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT {}

template <class _A1, __enable_if_t<!is_floating_point<_A1>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __constexpr_isinf(_A1 __lcpp_x) _NOEXCEPT {}

#if _LIBCPP_STD_VER >= 20
template <typename _Fp>
_LIBCPP_HIDE_FROM_ABI constexpr _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {}

_LIBCPP_HIDE_FROM_ABI inline constexpr float lerp(float __a, float __b, float __t) _NOEXCEPT {}

_LIBCPP_HIDE_FROM_ABI inline constexpr double lerp(double __a, double __b, double __t) _NOEXCEPT {}

_LIBCPP_HIDE_FROM_ABI inline constexpr long double lerp(long double __a, long double __b, long double __t) _NOEXCEPT {}

template <class _A1, class _A2, class _A3>
inline _LIBCPP_HIDE_FROM_ABI constexpr
    typename enable_if_t< is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && is_arithmetic<_A3>::value,
                          __promote<_A1, _A2, _A3> >::type
    lerp(_A1 __a, _A2 __b, _A3 __t) noexcept {}
#endif // _LIBCPP_STD_VER >= 20

_LIBCPP_END_NAMESPACE_STD

_LIBCPP_POP_MACROS

#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
#  include <type_traits>
#endif

#endif // _LIBCPP_CMATH