[c.math] (original) (raw)
26.8.1 Header synopsis [cmath.syn]
namespace std { using float_t = see below; using double_t = see below; }
#define HUGE_VAL see below #define HUGE_VALF see below #define HUGE_VALL see below #define INFINITY see below #define NAN see below #define FP_INFINITE see below #define FP_NAN see below #define FP_NORMAL see below #define FP_SUBNORMAL see below #define FP_ZERO see below #define FP_FAST_FMA see below #define FP_FAST_FMAF see below #define FP_FAST_FMAL see below #define FP_ILOGB0 see below #define FP_ILOGBNAN see below #define MATH_ERRNO see below #define MATH_ERREXCEPT see below
#define math_errhandling see below
namespace std {
float acos(float x);
double acos(double x);
long double acos(long double x);
float acosf(float x);
long double acosl(long double x);
float asin(float x);
double asin(double x);
long double asin(long double x);
float asinf(float x);
long double asinl(long double x);
float atan(float x);
double atan(double x);
long double atan(long double x);
float atanf(float x);
long double atanl(long double x);
float atan2(float y, float x);
double atan2(double y, double x);
long double atan2(long double y, long double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
float cos(float x);
double cos(double x);
long double cos(long double x);
float cosf(float x);
long double cosl(long double x);
float sin(float x);
double sin(double x);
long double sin(long double x);
float sinf(float x);
long double sinl(long double x);
float tan(float x);
double tan(double x);
long double tan(long double x);
float tanf(float x);
long double tanl(long double x);
float acosh(float x);
double acosh(double x);
long double acosh(long double x);
float acoshf(float x);
long double acoshl(long double x);
float asinh(float x);
double asinh(double x);
long double asinh(long double x);
float asinhf(float x);
long double asinhl(long double x);
float atanh(float x);
double atanh(double x);
long double atanh(long double x);
float atanhf(float x);
long double atanhl(long double x);
float cosh(float x);
double cosh(double x);
long double cosh(long double x);
float coshf(float x);
long double coshl(long double x);
float sinh(float x);
double sinh(double x);
long double sinh(long double x);
float sinhf(float x);
long double sinhl(long double x);
float tanh(float x);
double tanh(double x);
long double tanh(long double x);
float tanhf(float x);
long double tanhl(long double x);
float exp(float x);
double exp(double x);
long double exp(long double x);
float expf(float x);
long double expl(long double x);
float exp2(float x);
double exp2(double x);
long double exp2(long double x);
float exp2f(float x);
long double exp2l(long double x);
float expm1(float x);
double expm1(double x);
long double expm1(long double x);
float expm1f(float x);
long double expm1l(long double x);
float frexp(float value, int* exp);
double frexp(double value, int* exp);
long double frexp(long double value, int* exp);
float frexpf(float value, int* exp);
long double frexpl(long double value, int* exp);
int ilogb(float x);
int ilogb(double x);
int ilogb(long double x);
int ilogbf(float x);
int ilogbl(long double x);
float ldexp(float x, int exp);
double ldexp(double x, int exp);
long double ldexp(long double x, int exp);
float ldexpf(float x, int exp);
long double ldexpl(long double x, int exp);
float log(float x);
double log(double x);
long double log(long double x);
float logf(float x);
long double logl(long double x);
float log10(float x);
double log10(double x);
long double log10(long double x);
float log10f(float x);
long double log10l(long double x);
float log1p(float x);
double log1p(double x);
long double log1p(long double x);
float log1pf(float x);
long double log1pl(long double x);
float log2(float x);
double log2(double x);
long double log2(long double x);
float log2f(float x);
long double log2l(long double x);
float logb(float x);
double logb(double x);
long double logb(long double x);
float logbf(float x);
long double logbl(long double x);
float modf(float value, float* iptr);
double modf(double value, double* iptr);
long double modf(long double value, long double* iptr);
float modff(float value, float* iptr);
long double modfl(long double value, long double* iptr);
float scalbn(float x, int n);
double scalbn(double x, int n);
long double scalbn(long double x, int n);
float scalbnf(float x, int n);
long double scalbnl(long double x, int n);
float scalbln(float x, long int n);
double scalbln(double x, long int n);
long double scalbln(long double x, long int n);
float scalblnf(float x, long int n);
long double scalblnl(long double x, long int n);
float cbrt(float x);
double cbrt(double x);
long double cbrt(long double x);
float cbrtf(float x);
long double cbrtl(long double x);
int abs(int j); long int abs(long int j); long long int abs(long long int j); float abs(float j); double abs(double j); long double abs(long double j);
float fabs(float x);
double fabs(double x);
long double fabs(long double x);
float fabsf(float x);
long double fabsl(long double x);
float hypot(float x, float y);
double hypot(double x, double y);
long double hypot(long double x, long double y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);
float hypot(float x, float y, float z); double hypot(double x, double y, double z); long double hypot(long double x, long double y, long double z);
float pow(float x, float y);
double pow(double x, double y);
long double pow(long double x, long double y);
float powf(float x, float y);
long double powl(long double x, long double y);
float sqrt(float x);
double sqrt(double x);
long double sqrt(long double x);
float sqrtf(float x);
long double sqrtl(long double x);
float erf(float x);
double erf(double x);
long double erf(long double x);
float erff(float x);
long double erfl(long double x);
float erfc(float x);
double erfc(double x);
long double erfc(long double x);
float erfcf(float x);
long double erfcl(long double x);
float lgamma(float x);
double lgamma(double x);
long double lgamma(long double x);
float lgammaf(float x);
long double lgammal(long double x);
float tgamma(float x);
double tgamma(double x);
long double tgamma(long double x);
float tgammaf(float x);
long double tgammal(long double x);
float ceil(float x);
double ceil(double x);
long double ceil(long double x);
float ceilf(float x);
long double ceill(long double x);
float floor(float x);
double floor(double x);
long double floor(long double x);
float floorf(float x);
long double floorl(long double x);
float nearbyint(float x);
double nearbyint(double x);
long double nearbyint(long double x);
float nearbyintf(float x);
long double nearbyintl(long double x);
float rint(float x);
double rint(double x);
long double rint(long double x);
float rintf(float x);
long double rintl(long double x);
long int lrint(float x);
long int lrint(double x);
long int lrint(long double x);
long int lrintf(float x);
long int lrintl(long double x);
long long int llrint(float x);
long long int llrint(double x);
long long int llrint(long double x);
long long int llrintf(float x);
long long int llrintl(long double x);
float round(float x);
double round(double x);
long double round(long double x);
float roundf(float x);
long double roundl(long double x);
long int lround(float x);
long int lround(double x);
long int lround(long double x);
long int lroundf(float x);
long int lroundl(long double x);
long long int llround(float x);
long long int llround(double x);
long long int llround(long double x);
long long int llroundf(float x);
long long int llroundl(long double x);
float trunc(float x);
double trunc(double x);
long double trunc(long double x);
float truncf(float x);
long double truncl(long double x);
float fmod(float x, float y);
double fmod(double x, double y);
long double fmod(long double x, long double y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
float remainder(float x, float y);
double remainder(double x, double y);
long double remainder(long double x, long double y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
float remquo(float x, float y, int* quo);
double remquo(double x, double y, int* quo);
long double remquo(long double x, long double y, int* quo);
float remquof(float x, float y, int* quo);
long double remquol(long double x, long double y, int* quo);
float copysign(float x, float y);
double copysign(double x, double y);
long double copysign(long double x, long double y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
double nan(const char* tagp); float nanf(const char* tagp); long double nanl(const char* tagp);
float nextafter(float x, float y);
double nextafter(double x, double y);
long double nextafter(long double x, long double y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);
float nexttoward(float x, long double y);
double nexttoward(double x, long double y);
long double nexttoward(long double x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);
float fdim(float x, float y);
double fdim(double x, double y);
long double fdim(long double x, long double y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y);
float fmax(float x, float y);
double fmax(double x, double y);
long double fmax(long double x, long double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
float fmin(float x, float y);
double fmin(double x, double y);
long double fmin(long double x, long double y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
float fma(float x, float y, float z); double fma(double x, double y, double z); long double fma(long double x, long double y, long double z); float fmaf(float x, float y, float z); long double fmal(long double x, long double y, long double z);
constexpr float lerp(float a, float b, float t) noexcept; constexpr double lerp(double a, double b, double t) noexcept; constexpr long double lerp(long double a, long double b, long double t) noexcept;
int fpclassify(float x); int fpclassify(double x); int fpclassify(long double x);
bool isfinite(float x); bool isfinite(double x); bool isfinite(long double x);
bool isinf(float x); bool isinf(double x); bool isinf(long double x);
bool isnan(float x); bool isnan(double x); bool isnan(long double x);
bool isnormal(float x); bool isnormal(double x); bool isnormal(long double x);
bool signbit(float x); bool signbit(double x); bool signbit(long double x);
bool isgreater(float x, float y); bool isgreater(double x, double y); bool isgreater(long double x, long double y);
bool isgreaterequal(float x, float y); bool isgreaterequal(double x, double y); bool isgreaterequal(long double x, long double y);
bool isless(float x, float y); bool isless(double x, double y); bool isless(long double x, long double y);
bool islessequal(float x, float y); bool islessequal(double x, double y); bool islessequal(long double x, long double y);
bool islessgreater(float x, float y); bool islessgreater(double x, double y); bool islessgreater(long double x, long double y);
bool isunordered(float x, float y); bool isunordered(double x, double y); bool isunordered(long double x, long double y);
double assoc_laguerre(unsigned n, unsigned m, double x); float assoc_laguerref(unsigned n, unsigned m, float x); long double assoc_laguerrel(unsigned n, unsigned m, long double x);
double assoc_legendre(unsigned l, unsigned m, double x); float assoc_legendref(unsigned l, unsigned m, float x); long double assoc_legendrel(unsigned l, unsigned m, long double x);
double beta(double x, double y); float betaf(float x, float y); long double betal(long double x, long double y);
double comp_ellint_1(double k); float comp_ellint_1f(float k); long double comp_ellint_1l(long double k);
double comp_ellint_2(double k); float comp_ellint_2f(float k); long double comp_ellint_2l(long double k);
double comp_ellint_3(double k, double nu); float comp_ellint_3f(float k, float nu); long double comp_ellint_3l(long double k, long double nu);
double cyl_bessel_i(double nu, double x); float cyl_bessel_if(float nu, float x); long double cyl_bessel_il(long double nu, long double x);
double cyl_bessel_j(double nu, double x); float cyl_bessel_jf(float nu, float x); long double cyl_bessel_jl(long double nu, long double x);
double cyl_bessel_k(double nu, double x); float cyl_bessel_kf(float nu, float x); long double cyl_bessel_kl(long double nu, long double x);
double cyl_neumann(double nu, double x); float cyl_neumannf(float nu, float x); long double cyl_neumannl(long double nu, long double x);
double ellint_1(double k, double phi); float ellint_1f(float k, float phi); long double ellint_1l(long double k, long double phi);
double ellint_2(double k, double phi); float ellint_2f(float k, float phi); long double ellint_2l(long double k, long double phi);
double ellint_3(double k, double nu, double phi); float ellint_3f(float k, float nu, float phi); long double ellint_3l(long double k, long double nu, long double phi);
double expint(double x); float expintf(float x); long double expintl(long double x);
double hermite(unsigned n, double x); float hermitef(unsigned n, float x); long double hermitel(unsigned n, long double x);
double laguerre(unsigned n, double x); float laguerref(unsigned n, float x); long double laguerrel(unsigned n, long double x);
double legendre(unsigned l, double x); float legendref(unsigned l, float x); long double legendrel(unsigned l, long double x);
double riemann_zeta(double x); float riemann_zetaf(float x); long double riemann_zetal(long double x);
double sph_bessel(unsigned n, double x); float sph_besself(unsigned n, float x); long double sph_bessell(unsigned n, long double x);
double sph_legendre(unsigned l, unsigned m, double theta); float sph_legendref(unsigned l, unsigned m, float theta); long double sph_legendrel(unsigned l, unsigned m, long double theta);
double sph_neumann(unsigned n, double x); float sph_neumannf(unsigned n, float x); long double sph_neumannl(unsigned n, long double x); }
The contents and meaning of the header <cmath>are the same as the C standard library header <math.h>, with the addition of a three-dimensional hypotenuse function and the mathematical special functions described in [sf.cmath].
[ Note
:
Several functions have additional overloads in this document, but they have the same behavior as in the C standard library.
— end note
]
For each set of overloaded functions within <cmath>, with the exception of abs, there shall be additional overloads sufficient to ensure:
- If any argument of arithmetic type corresponding to a double parameter has type long double, then all arguments of arithmetic type corresponding to double parameters are effectively cast to long double.
- Otherwise, if any argument of arithmetic type corresponding to a double parameter has type double or an integer type, then all arguments of arithmetic type corresponding to double parameters are effectively cast to double.
- [ Note
: Otherwise, all arguments of arithmetic type corresponding to double parameters have type float. — end note
]
[ Note
: abs is exempted from these rules in order to stay compatible with C. — end note
]
See also:ISO C 7.12
26.8.2 Absolute values [c.math.abs]
[ Note
:
The headers <cstdlib> ([cstdlib.syn]) and<cmath> ([cmath.syn]) declare the functions described in this subclause.
— end note
]
int abs(int j);long int abs(long int j);long long int abs(long long int j);float abs(float j);double abs(double j);long double abs(long double j);
Effects:The absfunctions have the semantics specified in the C standard library for the functions abs, labs, llabs,fabsf, fabs, and fabsl.
Remarks:If abs() is called with an argument of type Xfor which is_unsigned_v<X> is true and if X cannot be converted to intby integral promotion, the program is ill-formed.
[ Note
:
Arguments that can be promoted to int are permitted for compatibility with C.
— end note
]
See also: ISO C 7.12.7.2, 7.22.6.1
26.8.3 Three-dimensional hypotenuse [c.math.hypot3]
float hypot(float x, float y, float z);double hypot(double x, double y, double z);long double hypot(long double x, long double y, long double z);
26.8.4 Linear interpolation [c.math.lerp]
constexpr float lerp(float a, float b, float t) noexcept;constexpr double lerp(double a, double b, double t) noexcept;constexpr long double lerp(long double a, long double b, long double t) noexcept;
Remarks:Let r be the value returned.
If isfinite(a) && isfinite(b), then:
- If t == 0, then r == a.
- If t == 1, then r == b.
- If t >= 0 && t <= 1, then isfinite(r).
- If isfinite(t) && a == b, then r == a.
- If isfinite(t) || !isnan(t) && b-a != 0, then !isnan(r).
Let CMP(x,y) be 1 if x > y,-1 if x < y, and 0 otherwise.
For any t1 and t2, the product ofCMP(lerp(a, b, t2), lerp(a, b, t1)),CMP(t2, t1), andCMP(b, a)is non-negative.
26.8.5 Classification / comparison functions [c.math.fpclass]
The classification / comparison functions behave the same as the C macros with the corresponding names defined in the C standard library.
Each function is overloaded for the three floating-point types.
See also:ISO C 7.12.3, 7.12.4
26.8.6 Mathematical special functions [sf.cmath]
If any argument value to any of the functions specified in this subclause is a NaN (Not a Number), the function shall return a NaN but it shall not report a domain error.
Otherwise, the function shall report a domain error for just those argument values for which:
- the function description's Returns: clause explicitly specifies a domain and those argument values fall outside the specified domain, or
- the corresponding mathematical function value has a nonzero imaginary component, or
- the corresponding mathematical function is not mathematically defined.254
Unless otherwise specified, each function is defined for all finite values, for negative infinity, and for positive infinity.
26.8.6.1 Associated Laguerre polynomials [sf.cmath.assoc.laguerre]
double assoc_laguerre(unsigned n, unsigned m, double x);float assoc_laguerref(unsigned n, unsigned m, float x);long double assoc_laguerrel(unsigned n, unsigned m, long double x);
Effects:These functions compute the associated Laguerre polynomials of their respective argumentsn, m, and x.
Returns:
wheren is n,m is m, andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if n >= 128 or if m >= 128.
26.8.6.2 Associated Legendre functions [sf.cmath.assoc.legendre]
double assoc_legendre(unsigned l, unsigned m, double x);float assoc_legendref(unsigned l, unsigned m, float x);long double assoc_legendrel(unsigned l, unsigned m, long double x);
Effects:These functions compute the associated Legendre functions of their respective argumentsl, m, and x.
Returns:
wherel is l,m is m, andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if l >= 128.
26.8.6.3 Beta function [sf.cmath.beta]
double beta(double x, double y);float betaf(float x, float y);long double betal(long double x, long double y);
Effects:These functions compute the beta function of their respective argumentsx and y.
Returns:
wherex is x andy is y.
26.8.6.4 Complete elliptic integral of the first kind [sf.cmath.comp.ellint.1]
double comp_ellint_1(double k);float comp_ellint_1f(float k);long double comp_ellint_1l(long double k);
Effects:These functions compute the complete elliptic integral of the first kind of their respective argumentsk.
26.8.6.5 Complete elliptic integral of the second kind [sf.cmath.comp.ellint.2]
double comp_ellint_2(double k);float comp_ellint_2f(float k);long double comp_ellint_2l(long double k);
Effects:These functions compute the complete elliptic integral of the second kind of their respective argumentsk.
26.8.6.6 Complete elliptic integral of the third kind [sf.cmath.comp.ellint.3]
double comp_ellint_3(double k, double nu);float comp_ellint_3f(float k, float nu);long double comp_ellint_3l(long double k, long double nu);
Effects:These functions compute the complete elliptic integral of the third kind of their respective argumentsk and nu.
Returns:
wherek is k andν is nu.
26.8.6.7 Regular modified cylindrical Bessel functions [sf.cmath.cyl.bessel.i]
double cyl_bessel_i(double nu, double x);float cyl_bessel_if(float nu, float x);long double cyl_bessel_il(long double nu, long double x);
Effects:These functions compute the regular modified cylindrical Bessel functions of their respective argumentsnu and x.
Returns:
whereν is nu andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if nu >= 128.
26.8.6.8 Cylindrical Bessel functions of the first kind [sf.cmath.cyl.bessel.j]
double cyl_bessel_j(double nu, double x);float cyl_bessel_jf(float nu, float x);long double cyl_bessel_jl(long double nu, long double x);
Effects:These functions compute the cylindrical Bessel functions of the first kind of their respective argumentsnu and x.
Returns:
whereν is nu andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if nu >= 128.
26.8.6.9 Irregular modified cylindrical Bessel functions [sf.cmath.cyl.bessel.k]
double cyl_bessel_k(double nu, double x);float cyl_bessel_kf(float nu, float x);long double cyl_bessel_kl(long double nu, long double x);
Effects:These functions compute the irregular modified cylindrical Bessel functions of their respective argumentsnu and x.
Returns:
whereν is nu andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if nu >= 128.
26.8.6.10 Cylindrical Neumann functions [sf.cmath.cyl.neumann]
double cyl_neumann(double nu, double x);float cyl_neumannf(float nu, float x);long double cyl_neumannl(long double nu, long double x);
Effects:These functions compute the cylindrical Neumann functions, also known as the cylindrical Bessel functions of the second kind, of their respective argumentsnu and x.
Returns:
whereν is nu andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if nu >= 128.
26.8.6.11 Incomplete elliptic integral of the first kind [sf.cmath.ellint.1]
double ellint_1(double k, double phi);float ellint_1f(float k, float phi);long double ellint_1l(long double k, long double phi);
Effects:These functions compute the incomplete elliptic integral of the first kind of their respective argumentsk and phi (phi measured in radians).
Returns:
wherek is k andφ is phi.
26.8.6.12 Incomplete elliptic integral of the second kind [sf.cmath.ellint.2]
double ellint_2(double k, double phi);float ellint_2f(float k, float phi);long double ellint_2l(long double k, long double phi);
Effects:These functions compute the incomplete elliptic integral of the second kind of their respective argumentsk and phi (phi measured in radians).
Returns:
wherek is k andφ is phi.
26.8.6.13 Incomplete elliptic integral of the third kind [sf.cmath.ellint.3]
double ellint_3(double k, double nu, double phi);float ellint_3f(float k, float nu, float phi);long double ellint_3l(long double k, long double nu, long double phi);
Effects:These functions compute the incomplete elliptic integral of the third kind of their respective argumentsk, nu, and phi (phi measured in radians).
Returns:
whereν is nu,k is k, andφ is phi.
26.8.6.14 Exponential integral [sf.cmath.expint]
double expint(double x);float expintf(float x);long double expintl(long double x);
Effects:These functions compute the exponential integral of their respective argumentsx.
26.8.6.15 Hermite polynomials [sf.cmath.hermite]
double hermite(unsigned n, double x);float hermitef(unsigned n, float x);long double hermitel(unsigned n, long double x);
Effects:These functions compute the Hermite polynomials of their respective argumentsn and x.
Returns:
wheren is n andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if n >= 128.
26.8.6.16 Laguerre polynomials [sf.cmath.laguerre]
double laguerre(unsigned n, double x);float laguerref(unsigned n, float x);long double laguerrel(unsigned n, long double x);
Effects:These functions compute the Laguerre polynomials of their respective argumentsn and x.
Returns:
wheren is n andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if n >= 128.
26.8.6.17 Legendre polynomials [sf.cmath.legendre]
double legendre(unsigned l, double x);float legendref(unsigned l, float x);long double legendrel(unsigned l, long double x);
Effects:These functions compute the Legendre polynomials of their respective argumentsl and x.
Returns:
wherel is l andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if l >= 128.
26.8.6.18 Riemann zeta function [sf.cmath.riemann.zeta]
double riemann_zeta(double x);float riemann_zetaf(float x);long double riemann_zetal(long double x);
Effects:These functions compute the Riemann zeta function of their respective argumentsx.
26.8.6.19 Spherical Bessel functions of the first kind [sf.cmath.sph.bessel]
double sph_bessel(unsigned n, double x);float sph_besself(unsigned n, float x);long double sph_bessell(unsigned n, long double x);
Effects:These functions compute the spherical Bessel functions of the first kind of their respective argumentsn and x.
Returns:
wheren is n andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if n >= 128.
26.8.6.20 Spherical associated Legendre functions [sf.cmath.sph.legendre]
double sph_legendre(unsigned l, unsigned m, double theta);float sph_legendref(unsigned l, unsigned m, float theta);long double sph_legendrel(unsigned l, unsigned m, long double theta);
Effects:These functions compute the spherical associated Legendre functions of their respective argumentsl, m, and theta (theta measured in radians).
Returns:
where
andl is l,m is m, andθ is theta.
Remarks:The effect of calling each of these functions is implementation-defined if l >= 128.
26.8.6.21 Spherical Neumann functions [sf.cmath.sph.neumann]
double sph_neumann(unsigned n, double x);float sph_neumannf(unsigned n, float x);long double sph_neumannl(unsigned n, long double x);
Effects:These functions compute the spherical Neumann functions, also known as the spherical Bessel functions of the second kind, of their respective argumentsn and x.
Returns:
wheren is n andx is x.
Remarks:The effect of calling each of these functions is implementation-defined if n >= 128.