Standard library header <cmath>
This header was originally in the C standard library as <math.h>.
This header is part of the numeric library.
Types | |
float_t (C++11) | most efficient floating-point type at least as wide as float (typedef) |
double_t (C++11) | most efficient floating-point type at least as wide as double (typedef) |
Macros | |
(C++11)(C++11) | indicates the overflow value for float, double and longdouble respectively (macro constant) |
(C++11) | evaluates to positive infinity or the value guaranteed to overflow a float (macro constant) |
(C++11) | evaluates to a quiet NaN of type float (macro constant) |
(C++11)(C++11)(C++11) | defines the error handling mechanism used by the common mathematical functions (macro constant) |
Classification | |
(C++11)(C++11)(C++11)(C++11)(C++11) | indicates a floating-point category (macro constant) |
Functions | |
Basic operations | |
(C++11)(C++11) | absolute value of a floating point value (|x|) (function) |
(C++11)(C++11) | remainder of the floating point division operation (function) |
(C++11)(C++11)(C++11) | signed remainder of the division operation (function) |
(C++11)(C++11)(C++11) | signed remainder as well as the three last bits of the division operation (function) |
(C++11)(C++11)(C++11) | fused multiply-add operation (function) |
(C++11)(C++11)(C++11) | larger of two floating-point values (function) |
(C++11)(C++11)(C++11) | smaller of two floating point values (function) |
(C++11)(C++11)(C++11) | positive difference of two floating point values (max(0, x-y)) (function) |
(C++11)(C++11)(C++11) | not-a-number (NaN) (function) |
Linear interpolation | |
(C++20) | linear interpolation function (function) |
Exponential functions | |
(C++11)(C++11) | returns e raised to the given power (ex) (function) |
(C++11)(C++11)(C++11) | returns 2 raised to the given power (2x) (function) |
(C++11)(C++11)(C++11) | returns e raised to the given power, minus 1 (ex-1) (function) |
(C++11)(C++11) | computes natural (base e) logarithm (ln(x)) (function) |
(C++11)(C++11) | computes common (base 10) logarithm (log10(x)) (function) |
(C++11)(C++11)(C++11) | base 2 logarithm of the given number (log2(x)) (function) |
(C++11)(C++11)(C++11) | natural logarithm (to base e) of 1 plus the given number (ln(1+x)) (function) |
Power functions | |
(C++11)(C++11) | raises a number to the given power (xy) (function) |
(C++11)(C++11) | computes square root (√x) (function) |
(C++11)(C++11)(C++11) | computes cube root (3√x) (function) |
(C++11)(C++11)(C++11) | computes hypotenuse √x2 +y2 and √x2 +y2 +z2 (since C++17) (function) |
Trigonometric functions | |
(C++11)(C++11) | computes sine (sin(x)) (function) |
(C++11)(C++11) | computes cosine (cos(x)) (function) |
(C++11)(C++11) | computes tangent (tan(x)) (function) |
(C++11)(C++11) | computes arc sine (arcsin(x)) (function) |
(C++11)(C++11) | computes arc cosine (arccos(x)) (function) |
(C++11)(C++11) | computes arc tangent (arctan(x)) (function) |
(C++11)(C++11) | arc tangent, using signs to determine quadrants (function) |
Hyperbolic functions | |
(C++11)(C++11) | computes hyperbolic sine (sinh(x)) (function) |
(C++11)(C++11) | computes hyperbolic cosine (cosh(x)) (function) |
(C++11)(C++11) | computes hyperbolic tangent (tanh(x)) (function) |
(C++11)(C++11)(C++11) | computes the inverse hyperbolic sine (arsinh(x)) (function) |
(C++11)(C++11)(C++11) | computes the inverse hyperbolic cosine (arcosh(x)) (function) |
(C++11)(C++11)(C++11) | computes the inverse hyperbolic tangent (artanh(x)) (function) |
Error and gamma functions | |
(C++11)(C++11)(C++11) | error function (function) |
(C++11)(C++11)(C++11) | complementary error function (function) |
(C++11)(C++11)(C++11) | gamma function (function) |
(C++11)(C++11)(C++11) | natural logarithm of the gamma function (function) |
Nearest integer floating-point operations | |
(C++11)(C++11) | nearest integer not less than the given value (function) |
(C++11)(C++11) | nearest integer not greater than the given value (function) |
(C++11)(C++11)(C++11) | nearest integer not greater in magnitude than the given value (function) |
(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11) | nearest integer, rounding away from zero in halfway cases (function) |
(C++11)(C++11)(C++11) | nearest integer using current rounding mode (function) |
(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11)(C++11) | nearest integer using current rounding mode with exception if the result differs (function) |
Floating-point manipulation functions | |
(C++11)(C++11) | decomposes a number into significand and base-2 exponent (function) |
(C++11)(C++11) | multiplies a number by 2 raised to an integral power (function) |
(C++11)(C++11) | decomposes a number into integer and fractional parts (function) |
(C++11)(C++11)(C++11)(C++11)(C++11)(C++11) | multiplies a number by FLT_RADIX raised to a power (function) |
(C++11)(C++11)(C++11) | extracts exponent of the number (function) |
(C++11)(C++11)(C++11) | extracts exponent of the number (function) |
(C++11)(C++11)(C++11)(C++11)(C++11)(C++11) | next representable floating-point value towards the given value (function) |
(C++11)(C++11)(C++11) | copies the sign of a floating point value (function) |
Classification and comparison | |
(C++11) | categorizes the given floating-point value (function) |
(C++11) | checks if the given number has finite value (function) |
(C++11) | checks if the given number is infinite (function) |
(C++11) | checks if the given number is NaN (function) |
(C++11) | checks if the given number is normal (function) |
(C++11) | checks if the given number is negative (function) |
(C++11) | checks if the first floating-point argument is greater than the second (function) |
(C++11) | checks if the first floating-point argument is greater or equal than the second (function) |
(C++11) | checks if the first floating-point argument is less than the second (function) |
(C++11) | checks if the first floating-point argument is less or equal than the second (function) |
(C++11) | checks if the first floating-point argument is less or greater than the second (function) |
(C++11) | checks if two floating-point values are unordered (function) |
Mathematical special functions | |
(C++17)(C++17)(C++17) | associated Laguerre polynomials (function) |
(C++17)(C++17)(C++17) | associated Legendre polynomials (function) |
(C++17)(C++17)(C++17) | beta function (function) |
(C++17)(C++17)(C++17) | (complete) elliptic integral of the first kind (function) |
(C++17)(C++17)(C++17) | (complete) elliptic integral of the second kind (function) |
(C++17)(C++17)(C++17) | (complete) elliptic integral of the third kind (function) |
(C++17)(C++17)(C++17) | regular modified cylindrical Bessel functions (function) |
(C++17)(C++17)(C++17) | cylindrical Bessel functions (of the first kind) (function) |
(C++17)(C++17)(C++17) | irregular modified cylindrical Bessel functions (function) |
(C++17)(C++17)(C++17) | cylindrical Neumann functions (function) |
(C++17)(C++17)(C++17) | (incomplete) elliptic integral of the first kind (function) |
(C++17)(C++17)(C++17) | (incomplete) elliptic integral of the second kind (function) |
(C++17)(C++17)(C++17) | (incomplete) elliptic integral of the third kind (function) |
(C++17)(C++17)(C++17) | exponential integral (function) |
(C++17)(C++17)(C++17) | Hermite polynomials (function) |
(C++17)(C++17)(C++17) | Legendre polynomials (function) |
(C++17)(C++17)(C++17) | Laguerre polynomials (function) |
(C++17)(C++17)(C++17) | Riemann zeta function (function) |
(C++17)(C++17)(C++17) | spherical Bessel functions (of the first kind) (function) |
(C++17)(C++17)(C++17) | spherical associated Legendre functions (function) |
(C++17)(C++17)(C++17) | spherical Neumann functions (function) |
[edit]Synopsis
For each function with at least one parameter of type /* floating-point-type */, an overload for each cv-unqualified floating-point type is provided where all uses of /* floating-point-type */ in the function signature are replaced with that floating-point type.
For each function with at least one parameter of type /* floating-point-type */ other than std::abs
, additional overloads are provided to ensure that, if every argument corresponding to a /* floating-point-type */ parameter has arithmetic type, then every such argument is effectively cast to the floating-point type with the greatest floating-point conversion rank and greatest floating-point conversion subrank among the types of all such arguments, where arguments of integer type are considered to have the same floating-point conversion rank as double. If no such floating-point type with the greatest rank and subrank exists, then overload resolution does not result in a usable candidate from the provided overloads.
namespace std {using float_t =/* see description */;using double_t =/* see description */;} #define HUGE_VAL /* see description */#define HUGE_VALF /* see description */#define HUGE_VALL /* see description */#define INFINITY /* see description */#define NAN /* see description */#define FP_INFINITE /* see description */#define FP_NAN /* see description */#define FP_NORMAL /* see description */#define FP_SUBNORMAL /* see description */#define FP_ZERO /* see description */#define FP_FAST_FMA /* see description */#define FP_FAST_FMAF /* see description */#define FP_FAST_FMAL /* see description */#define FP_ILOGB0 /* see description */#define FP_ILOGBNAN /* see description */#define MATH_ERRNO /* see description */#define MATH_ERREXCEPT /* see description */ #define math_errhandling /* see description */ namespace std {/* floating-point-type */ acos(/* floating-point-type */ x);float acosf(float x);longdouble acosl(longdouble x); /* floating-point-type */ asin(/* floating-point-type */ x);float asinf(float x);longdouble asinl(longdouble x); /* floating-point-type */ atan(/* floating-point-type */ x);float atanf(float x);longdouble atanl(longdouble x); /* floating-point-type */ atan2(/* floating-point-type */ y, /* floating-point-type */ x);float atan2f(float y, float x);longdouble atan2l(longdouble y, longdouble x); /* floating-point-type */ cos(/* floating-point-type */e x);float cosf(float x);longdouble cosl(longdouble x); /* floating-point-type */ sin(/* floating-point-type */ x);float sinf(float x);longdouble sinl(longdouble x); /* floating-point-type */ tan(/* floating-point-type */ x);float tanf(float x);longdouble tanl(longdouble x); /* floating-point-type */ acosh(/* floating-point-type */ x);float acoshf(float x);longdouble acoshl(longdouble x); /* floating-point-type */ asinh(/* floating-point-type */ x);float asinhf(float x);longdouble asinhl(longdouble x); /* floating-point-type */ atanh(/* floating-point-type */ x);float atanhf(float x);longdouble atanhl(longdouble x); /* floating-point-type */ cosh(/* floating-point-type */ x);float coshf(float x);longdouble coshl(longdouble x); /* floating-point-type */ sinh(/* floating-point-type */ x);float sinhf(float x);longdouble sinhl(longdouble x); /* floating-point-type */ tanh(/* floating-point-type */ x);float tanhf(float x);longdouble tanhl(longdouble x); /* floating-point-type */ exp(/* floating-point-type */ x);float expf(float x);longdouble expl(longdouble x); /* floating-point-type */ exp2(/* floating-point-type */ x);float exp2f(float x);longdouble exp2l(longdouble x); /* floating-point-type */ expm1(/* floating-point-type */ x);float expm1f(float x);longdouble expm1l(longdouble x); constexpr/* floating-point-type */ frexp(/* floating-point-type */ value, int* exp);constexprfloat frexpf(float value, int* exp);constexprlongdouble frexpl(longdouble value, int* exp); constexprint ilogb(/* floating-point-type */ x);constexprint ilogbf(float x);constexprint ilogbl(longdouble x); constexpr/* floating-point-type */ ldexp(/* floating-point-type */ x, int exp);constexprfloat ldexpf(float x, int exp);constexprlongdouble ldexpl(longdouble x, int exp); /* floating-point-type */ log(/* floating-point-type */ x);float logf(float x);longdouble logl(longdouble x); /* floating-point-type */ log10(/* floating-point-type */ x);float log10f(float x);longdouble log10l(longdouble x); /* floating-point-type */ log1p(/* floating-point-type */ x);float log1pf(float x);longdouble log1pl(longdouble x); /* floating-point-type */ log2(/* floating-point-type */ x);float log2f(float x);longdouble log2l(longdouble x); constexpr/* floating-point-type */ logb(/* floating-point-type */ x);constexprfloat logbf(float x);constexprlongdouble logbl(longdouble x); constexpr/* floating-point-type */ modf(/* floating-point-type */ value, /* floating-point-type */* iptr);constexprfloat modff(float value, float* iptr);constexprlongdouble modfl(longdouble value, longdouble* iptr); constexpr/* floating-point-type */ scalbn(/* floating-point-type */ x, int n);constexprfloat scalbnf(float x, int n);constexprlongdouble scalbnl(longdouble x, int n); constexpr/* floating-point-type */ scalbln(/* floating-point-type */ x, longint n);constexprfloat scalblnf(float x, longint n);constexprlongdouble scalblnl(longdouble x, longint n); /* floating-point-type */ cbrt(/* floating-point-type */ x);float cbrtf(float x);longdouble cbrtl(longdouble x); // absolute valuesconstexprint abs(int j);// freestandingconstexprlongint abs(longint j);// freestandingconstexprlonglongint abs(longlongint j);// freestandingconstexpr/* floating-point-type */ abs(/* floating-point-type */ j);// freestanding-deleted constexpr/* floating-point-type */ fabs(/* floating-point-type */ x);constexprfloat fabsf(float x);constexprlongdouble fabsl(longdouble x); /* floating-point-type */ hypot(/* floating-point-type */ x, /* floating-point-type */ y);float hypotf(float x, float y);longdouble hypotl(longdouble x, longdouble y); // three-dimensional hypotenusefloat hypot(/* floating-point-type */ x, /* floating-point-type */ y, /* floating-point-type */ z); /* floating-point-type */ pow(/* floating-point-type */ x, /* floating-point-type */ y);float powf(float x, float y);longdouble powl(longdouble x, longdouble y); /* floating-point-type */ sqrt(/* floating-point-type */ x);float sqrtf(float x);longdouble sqrtl(longdouble x); /* floating-point-type */ erf(/* floating-point-type */ x);float erff(float x);longdouble erfl(longdouble x); /* floating-point-type */ erfc(/* floating-point-type */ x);float erfcf(float x);longdouble erfcl(longdouble x); /* floating-point-type */ lgamma(/* floating-point-type */ x);float lgammaf(float x);longdouble lgammal(longdouble x); /* floating-point-type */ tgamma(/* floating-point-type */ x);float tgammaf(float x);longdouble tgammal(longdouble x); constexpr/* floating-point-type */ ceil(/* floating-point-type */ x);constexprfloat ceilf(float x);constexprlongdouble ceill(longdouble x); constexpr/* floating-point-type */ floor(/* floating-point-type */ x);constexprfloat floorf(float x);constexprlongdouble floorl(longdouble x); /* floating-point-type */ nearbyint(/* floating-point-type */ x);float nearbyintf(float x);longdouble nearbyintl(longdouble x); /* floating-point-type */ rint(/* floating-point-type */ x);float rintf(float x);longdouble rintl(longdouble x); longint lrint(/* floating-point-type */ x);longint lrintf(float x);longint lrintl(longdouble x); longlongint llrint(/* floating-point-type */ x);longlongint llrintf(float x);longlongint llrintl(longdouble x); constexpr/* floating-point-type */ round(/* floating-point-type */ x);constexprfloat roundf(float x);constexprlongdouble roundl(longdouble x); constexprlongint lround(/* floating-point-type */ x);constexprlongint lroundf(float x);constexprlongint lroundl(longdouble x); constexprlonglongint llround(/* floating-point-type */ x);constexprlonglongint llroundf(float x);constexprlonglongint llroundl(longdouble x); constexpr/* floating-point-type */ trunc(/* floating-point-type */ x);constexprfloat truncf(float x);constexprlongdouble truncl(longdouble x); constexpr/* floating-point-type */ fmod(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat fmodf(float x, float y);constexprlongdouble fmodl(longdouble x, longdouble y); constexpr/* floating-point-type */ remainder(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat remainderf(float x, float y);constexprlongdouble remainderl(longdouble x, longdouble y); constexpr/* floating-point-type */ remquo(/* floating-point-type */ x, /* floating-point-type */ y, int* quo);constexprfloat remquof(float x, float y, int* quo);constexprlongdouble remquol(longdouble x, longdouble y, int* quo); constexpr/* floating-point-type */ copysign(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat copysignf(float x, float y);constexprlongdouble copysignl(longdouble x, longdouble y); double nan(constchar* tagp);float nanf(constchar* tagp);longdouble nanl(constchar* tagp); constexpr/* floating-point-type */ nextafter(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat nextafterf(float x, float y);constexprlongdouble nextafterl(longdouble x, longdouble y); constexpr/* floating-point-type */ nexttoward(/* floating-point-type */ x, longdouble y);constexprfloat nexttowardf(float x, longdouble y);constexprlongdouble nexttowardl(longdouble x, longdouble y); constexpr/* floating-point-type */ fdim(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat fdimf(float x, float y);constexprlongdouble fdiml(longdouble x, longdouble y); constexpr/* floating-point-type */ fmax(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat fmaxf(float x, float y);constexprlongdouble fmaxl(longdouble x, longdouble y); constexpr/* floating-point-type */ fmin(/* floating-point-type */ x, /* floating-point-type */ y);constexprfloat fminf(float x, float y);constexprlongdouble fminl(longdouble x, longdouble y); constexpr/* floating-point-type */ fma(/* floating-point-type */ x, /* floating-point-type */ y, /* floating-point-type */ z);constexprfloat fmaf(float x, float y, float z);constexprlongdouble fmal(longdouble x, longdouble y, longdouble z); // linear interpolationconstexpr/* floating-point-type */ lerp(/* floating-point-type */ a, /* floating-point-type */ b, /* floating-point-type */ t)noexcept; // classification / comparison functionsconstexprint fpclassify(/* floating-point-type */ x); constexprbool isfinite(/* floating-point-type */ x); constexprbool isinf(/* floating-point-type */ x); constexprbool isnan(/* floating-point-type */ x); constexprbool isnormal(/* floating-point-type */ x); constexprbool signbit(/* floating-point-type */ x); constexprbool isgreater(/* floating-point-type */ x, /* floating-point-type */ y); constexprbool isgreaterequal(/* floating-point-type */ x, /* floating-point-type */ y); constexprbool isless(/* floating-point-type */ x, /* floating-point-type */ y); constexprbool islessequal(/* floating-point-type */ x, /* floating-point-type */ y); constexprbool islessgreater(/* floating-point-type */ x, /* floating-point-type */ y); constexprbool isunordered(/* floating-point-type */ x, /* floating-point-type */ y); // mathematical special functions // associated Laguerre polynomials/* floating-point-type */ assoc_laguerre(unsigned n, unsigned m, /* floating-point-type */ x);float assoc_laguerref(unsigned n, unsigned m, float x);longdouble assoc_laguerrel(unsigned n, unsigned m, longdouble x); // associated Legendre functions/* floating-point-type */ assoc_legendre(unsigned l, unsigned m, /* floating-point-type */ x);float assoc_legendref(unsigned l, unsigned m, float x);longdouble assoc_legendrel(unsigned l, unsigned m, longdouble x); // beta function/* floating-point-type */ beta(/* floating-point-type */ x, /* floating-point-type */ y);float betaf(float x, float y);longdouble betal(longdouble x, longdouble y); // complete elliptic integral of the first kind/* floating-point-type */ comp_ellint_1(/* floating-point-type */ k);float comp_ellint_1f(float k);longdouble comp_ellint_1l(longdouble k); // complete elliptic integral of the second kind/* floating-point-type */ comp_ellint_2(/* floating-point-type */ k);float comp_ellint_2f(float k);longdouble comp_ellint_2l(longdouble k); // complete elliptic integral of the third kind/* floating-point-type */ comp_ellint_3(/* floating-point-type */ k, /* floating-point-type */ nu);float comp_ellint_3f(float k, float nu);longdouble comp_ellint_3l(longdouble k, longdouble nu); // regular modified cylindrical Bessel functions/* floating-point-type */ cyl_bessel_i(/* floating-point-type */ nu, /* floating-point-type */ x);float cyl_bessel_if(float nu, float x);longdouble cyl_bessel_il(longdouble nu, longdouble x); // cylindrical Bessel functions of the first kind/* floating-point-type */ cyl_bessel_j(/* floating-point-type */ nu, /* floating-point-type */ x);float cyl_bessel_jf(float nu, float x);longdouble cyl_bessel_jl(longdouble nu, longdouble x); // irregular modified cylindrical Bessel functions/* floating-point-type */ cyl_bessel_k(/* floating-point-type */ nu, /* floating-point-type */ x);float cyl_bessel_kf(float nu, float x);longdouble cyl_bessel_kl(longdouble nu, longdouble x); // cylindrical Neumann functions;// cylindrical Bessel functions of the second kind/* floating-point-type */ cyl_neumann(/* floating-point-type */ nu, /* floating-point-type */ x);float cyl_neumannf(float nu, float x);longdouble cyl_neumannl(longdouble nu, longdouble x); // incomplete elliptic integral of the first kind/* floating-point-type */ ellint_1(/* floating-point-type */ k, /* floating-point-type */ phi);float ellint_1f(float k, float phi);longdouble ellint_1l(longdouble k, longdouble phi); // incomplete elliptic integral of the second kind/* floating-point-type */ ellint_2(/* floating-point-type */ k, /* floating-point-type */ phi);float ellint_2f(float k, float phi);longdouble ellint_2l(longdouble k, longdouble phi); // incomplete elliptic integral of the third kind/* floating-point-type */ ellint_3(/* floating-point-type */ k, /* floating-point-type */ nu, /* floating-point-type */ phi);float ellint_3f(float k, float nu, float phi);longdouble ellint_3l(longdouble k, longdouble nu, longdouble phi); // exponential integral/* floating-point-type */ expint(/* floating-point-type */ x);float expintf(float x);longdouble expintl(longdouble x); // Hermite polynomials/* floating-point-type */ hermite(unsigned n, /* floating-point-type */ x);float hermitef(unsigned n, float x);longdouble hermitel(unsigned n, longdouble x); // Laguerre polynomials/* floating-point-type */ laguerre(unsigned n, /* floating-point-type */ x);float laguerref(unsigned n, float x);longdouble laguerrel(unsigned n, longdouble x); // Legendre polynomials/* floating-point-type */ legendre(unsigned l, /* floating-point-type */ x);float legendref(unsigned l, float x);longdouble legendrel(unsigned l, longdouble x); // Riemann zeta function/* floating-point-type */ riemann_zeta(/* floating-point-type */ x);float riemann_zetaf(float x);longdouble riemann_zetal(longdouble x); // spherical Bessel functions of the first kind/* floating-point-type */ sph_bessel(unsigned n, /* floating-point-type */ x);float sph_besself(unsigned n, float x);longdouble sph_bessell(unsigned n, longdouble x); // spherical associated Legendre functions/* floating-point-type */ sph_legendre(unsigned l, unsigned m, /* floating-point-type */ theta);float sph_legendref(unsigned l, unsigned m, float theta);longdouble sph_legendrel(unsigned l, unsigned m, longdouble theta); // spherical Neumann functions;// spherical Bessel functions of the second kind/* floating-point-type */ sph_neumann(unsigned n, /* floating-point-type */ x);float sph_neumannf(unsigned n, float x);longdouble sph_neumannl(unsigned n, longdouble x);}