Difference between revisions of "cpp/numeric/math"
From cppreference.com
D41D8CD98F (Talk | contribs) (Undo revision 109909 by 192.185.83.191 (talk)) |
m (→Notes: FTM fix: <complex> has its own `__cpp_lib_constexpr_complex` macro.) |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
===Functions=== | ===Functions=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc header | cstdlib}} | + | {{dsc header|cstdlib}} |
− | {{dsc inc | cpp/numeric/math/dsc abs}} | + | {{dsc inc|cpp/numeric/math/dsc abs}} |
− | {{dsc inc | cpp/numeric/math/dsc div}} | + | {{dsc inc|cpp/numeric/math/dsc div}} |
− | {{dsc header | cinttypes}} | + | {{dsc header|cinttypes}} |
− | {{dsc inc | cpp/numeric/math/dsc imaxabs}} | + | {{dsc inc|cpp/numeric/math/dsc imaxabs}} |
− | {{dsc inc | cpp/numeric/math/dsc imaxdiv}} | + | {{dsc inc|cpp/numeric/math/dsc imaxdiv}} |
− | {{dsc header | cmath}} | + | {{dsc header|cmath}} |
− | {{dsc h2 | Basic operations}} | + | {{dsc h2|Basic operations}} |
− | {{dsc inc | cpp/numeric/math/dsc fabs}} | + | {{dsc inc|cpp/numeric/math/dsc fabs}} |
− | {{dsc inc | cpp/numeric/math/dsc fmod}} | + | {{dsc inc|cpp/numeric/math/dsc fmod}} |
− | {{dsc inc | cpp/numeric/math/dsc remainder}} | + | {{dsc inc|cpp/numeric/math/dsc remainder}} |
− | {{dsc inc | cpp/numeric/math/dsc remquo}} | + | {{dsc inc|cpp/numeric/math/dsc remquo}} |
− | {{dsc inc | cpp/numeric/math/dsc fma}} | + | {{dsc inc|cpp/numeric/math/dsc fma}} |
− | {{dsc inc | cpp/numeric/math/dsc fmax}} | + | {{dsc inc|cpp/numeric/math/dsc fmax}} |
− | {{dsc inc | cpp/numeric/math/dsc fmin}} | + | {{dsc inc|cpp/numeric/math/dsc fmin}} |
− | {{dsc inc | cpp/numeric/math/dsc fdim}} | + | {{dsc inc|cpp/numeric/math/dsc fdim}} |
− | {{dsc inc | cpp/numeric/math/dsc fnan}} | + | {{dsc inc|cpp/numeric/math/dsc fnan}} |
− | {{dsc h2 | Exponential functions}} | + | {{dsc h2|Exponential functions}} |
− | {{dsc inc | cpp/numeric/math/dsc exp}} | + | {{dsc inc|cpp/numeric/math/dsc exp}} |
− | {{dsc inc | cpp/numeric/math/dsc exp2}} | + | {{dsc inc|cpp/numeric/math/dsc exp2}} |
− | {{dsc inc | cpp/numeric/math/dsc expm1}} | + | {{dsc inc|cpp/numeric/math/dsc expm1}} |
− | {{dsc inc | cpp/numeric/math/dsc log}} | + | {{dsc inc|cpp/numeric/math/dsc log}} |
− | {{dsc inc | cpp/numeric/math/dsc log10}} | + | {{dsc inc|cpp/numeric/math/dsc log10}} |
− | {{dsc inc | cpp/numeric/math/dsc log2}} | + | {{dsc inc|cpp/numeric/math/dsc log2}} |
− | {{dsc inc | cpp/numeric/math/dsc log1p}} | + | {{dsc inc|cpp/numeric/math/dsc log1p}} |
− | {{dsc h2 | Power functions}} | + | {{dsc h2|Power functions}} |
− | {{dsc inc | cpp/numeric/math/dsc pow}} | + | {{dsc inc|cpp/numeric/math/dsc pow}} |
− | {{dsc inc | cpp/numeric/math/dsc sqrt}} | + | {{dsc inc|cpp/numeric/math/dsc sqrt}} |
− | {{dsc inc | cpp/numeric/math/dsc cbrt}} | + | {{dsc inc|cpp/numeric/math/dsc cbrt}} |
− | {{dsc inc | cpp/numeric/math/dsc hypot}} | + | {{dsc inc|cpp/numeric/math/dsc hypot}} |
− | {{dsc h2 | Trigonometric functions}} | + | {{dsc h2|Trigonometric functions}} |
− | {{dsc inc | cpp/numeric/math/dsc sin}} | + | {{dsc inc|cpp/numeric/math/dsc sin}} |
− | {{dsc inc | cpp/numeric/math/dsc cos}} | + | {{dsc inc|cpp/numeric/math/dsc cos}} |
− | {{dsc inc | cpp/numeric/math/dsc tan}} | + | {{dsc inc|cpp/numeric/math/dsc tan}} |
− | {{dsc inc | cpp/numeric/math/dsc asin}} | + | {{dsc inc|cpp/numeric/math/dsc asin}} |
− | {{dsc inc | cpp/numeric/math/dsc acos}} | + | {{dsc inc|cpp/numeric/math/dsc acos}} |
− | {{dsc inc | cpp/numeric/math/dsc atan}} | + | {{dsc inc|cpp/numeric/math/dsc atan}} |
− | {{dsc inc | cpp/numeric/math/dsc atan2}} | + | {{dsc inc|cpp/numeric/math/dsc atan2}} |
− | {{dsc h2 | Hyperbolic functions}} | + | {{dsc h2|Hyperbolic functions}} |
− | {{dsc inc | cpp/numeric/math/dsc sinh}} | + | {{dsc inc|cpp/numeric/math/dsc sinh}} |
− | {{dsc inc | cpp/numeric/math/dsc cosh}} | + | {{dsc inc|cpp/numeric/math/dsc cosh}} |
− | {{dsc inc | cpp/numeric/math/dsc tanh}} | + | {{dsc inc|cpp/numeric/math/dsc tanh}} |
− | {{dsc inc | cpp/numeric/math/dsc asinh}} | + | {{dsc inc|cpp/numeric/math/dsc asinh}} |
− | {{dsc inc | cpp/numeric/math/dsc acosh}} | + | {{dsc inc|cpp/numeric/math/dsc acosh}} |
− | {{dsc inc | cpp/numeric/math/dsc atanh}} | + | {{dsc inc|cpp/numeric/math/dsc atanh}} |
− | {{dsc h2 | Error and gamma functions}} | + | {{dsc h2|Error and gamma functions}} |
− | {{dsc inc | cpp/numeric/math/dsc erf}} | + | {{dsc inc|cpp/numeric/math/dsc erf}} |
− | {{dsc inc | cpp/numeric/math/dsc erfc}} | + | {{dsc inc|cpp/numeric/math/dsc erfc}} |
− | {{dsc inc | cpp/numeric/math/dsc tgamma}} | + | {{dsc inc|cpp/numeric/math/dsc tgamma}} |
− | {{dsc inc | cpp/numeric/math/dsc lgamma}} | + | {{dsc inc|cpp/numeric/math/dsc lgamma}} |
− | {{dsc h2 | Nearest integer floating point operations}} | + | {{dsc h2|Nearest integer floating point operations}} |
− | {{dsc inc | cpp/numeric/math/dsc ceil}} | + | {{dsc inc|cpp/numeric/math/dsc ceil}} |
− | {{dsc inc | cpp/numeric/math/dsc floor}} | + | {{dsc inc|cpp/numeric/math/dsc floor}} |
− | {{dsc inc | cpp/numeric/math/dsc trunc}} | + | {{dsc inc|cpp/numeric/math/dsc trunc}} |
− | {{dsc inc | cpp/numeric/math/dsc round}} | + | {{dsc inc|cpp/numeric/math/dsc round}} |
− | {{dsc inc | cpp/numeric/math/dsc nearbyint}} | + | {{dsc inc|cpp/numeric/math/dsc nearbyint}} |
− | {{dsc inc | cpp/numeric/math/dsc rint}} | + | {{dsc inc|cpp/numeric/math/dsc rint}} |
− | {{dsc h2 | Floating point manipulation functions}} | + | {{dsc h2|Floating point manipulation functions}} |
− | {{dsc inc | cpp/numeric/math/dsc frexp}} | + | {{dsc inc|cpp/numeric/math/dsc frexp}} |
− | {{dsc inc | cpp/numeric/math/dsc ldexp}} | + | {{dsc inc|cpp/numeric/math/dsc ldexp}} |
− | {{dsc inc | cpp/numeric/math/dsc modf}} | + | {{dsc inc|cpp/numeric/math/dsc modf}} |
− | {{dsc inc | cpp/numeric/math/dsc scalbn}} | + | {{dsc inc|cpp/numeric/math/dsc scalbn}} |
− | {{dsc inc | cpp/numeric/math/dsc ilogb}} | + | {{dsc inc|cpp/numeric/math/dsc ilogb}} |
− | {{dsc inc | cpp/numeric/math/dsc logb}} | + | {{dsc inc|cpp/numeric/math/dsc logb}} |
− | {{dsc inc | cpp/numeric/math/dsc nextafter}} | + | {{dsc inc|cpp/numeric/math/dsc nextafter}} |
− | {{dsc inc | cpp/numeric/math/dsc copysign}} | + | {{dsc inc|cpp/numeric/math/dsc copysign}} |
− | {{dsc h2 | Classification and comparison}} | + | {{dsc h2|Classification and comparison}} |
− | {{dsc inc | cpp/numeric/math/dsc fpclassify}} | + | {{dsc inc|cpp/numeric/math/dsc fpclassify}} |
− | {{dsc inc | cpp/numeric/math/dsc isfinite}} | + | {{dsc inc|cpp/numeric/math/dsc isfinite}} |
− | {{dsc inc | cpp/numeric/math/dsc isinf}} | + | {{dsc inc|cpp/numeric/math/dsc isinf}} |
− | {{dsc inc | cpp/numeric/math/dsc isnan}} | + | {{dsc inc|cpp/numeric/math/dsc isnan}} |
− | {{dsc inc | cpp/numeric/math/dsc isnormal}} | + | {{dsc inc|cpp/numeric/math/dsc isnormal}} |
− | {{dsc inc | cpp/numeric/math/dsc signbit}} | + | {{dsc inc|cpp/numeric/math/dsc signbit}} |
− | {{dsc inc | cpp/numeric/math/dsc isgreater}} | + | {{dsc inc|cpp/numeric/math/dsc isgreater}} |
− | {{dsc inc | cpp/numeric/math/dsc isgreaterequal}} | + | {{dsc inc|cpp/numeric/math/dsc isgreaterequal}} |
− | {{dsc inc | cpp/numeric/math/dsc isless}} | + | {{dsc inc|cpp/numeric/math/dsc isless}} |
− | {{dsc inc | cpp/numeric/math/dsc islessequal}} | + | {{dsc inc|cpp/numeric/math/dsc islessequal}} |
− | {{dsc inc | cpp/numeric/math/dsc islessgreater}} | + | {{dsc inc|cpp/numeric/math/dsc islessgreater}} |
− | {{dsc inc | cpp/numeric/math/dsc isunordered}} | + | {{dsc inc|cpp/numeric/math/dsc isunordered}} |
{{dsc end}} | {{dsc end}} | ||
===Types=== | ===Types=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc header | cstdlib }} | + | {{dsc header|cstdlib}} |
− | {{dsc inc | cpp/numeric/math/dsc div_t}} | + | {{dsc inc|cpp/numeric/math/dsc div_t}} |
− | {{dsc inc | cpp/numeric/math/dsc ldiv_t}} | + | {{dsc inc|cpp/numeric/math/dsc ldiv_t}} |
− | {{dsc inc | cpp/numeric/math/dsc lldiv_t}} | + | {{dsc inc|cpp/numeric/math/dsc lldiv_t}} |
− | {{dsc header | cinttypes }} | + | {{dsc header|cinttypes}} |
− | {{dsc inc | cpp/numeric/math/dsc imaxdiv_t}} | + | {{dsc inc|cpp/numeric/math/dsc imaxdiv_t}} |
− | {{dsc header | cmath }} | + | {{dsc header|cmath}} |
− | {{dsc inc | cpp/numeric/math/dsc float_t}} | + | {{dsc inc|cpp/numeric/math/dsc float_t}} |
− | {{dsc inc | cpp/numeric/math/dsc double_t}} | + | {{dsc inc|cpp/numeric/math/dsc double_t}} |
{{dsc end}} | {{dsc end}} | ||
===Macro constants=== | ===Macro constants=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc header | cmath}} | + | {{dsc header|cmath}} |
− | {{dsc inc | cpp/numeric/math/dsc HUGE_VAL}}} | + | {{dsc inc|cpp/numeric/math/dsc HUGE_VAL}}} |
− | {{dsc inc | cpp/numeric/math/dsc INFINITY}}} | + | {{dsc inc|cpp/numeric/math/dsc INFINITY}}} |
− | {{dsc inc | cpp/numeric/math/dsc NAN}}} | + | {{dsc inc|cpp/numeric/math/dsc NAN}}} |
− | {{dsc inc | cpp/numeric/math/dsc math_errhandling}} | + | {{dsc inc|cpp/numeric/math/dsc math_errhandling}} |
− | {{dsc h2 | Classification}} | + | {{dsc h2|Classification}} |
− | {{dsc inc | cpp/numeric/math/dsc FP_categories}} | + | {{dsc inc|cpp/numeric/math/dsc FP_categories}} |
{{dsc end}} | {{dsc end}} | ||
+ | |||
+ | ===Notes=== | ||
+ | {{ftm begin|std=yea|comment=yes}} | ||
+ | {{ftm|__cpp_lib_constexpr_cmath|rowspan="2"|std=C++23|value=202202L|Constexpr for FP environment agnostic mathematical functions in {{header|cmath}} and {{header|cstdlib}}}} | ||
+ | {{ftm|-|std=C++26|value=202306L|Constexpr for most mathematical functions in {{header|cmath}}}} | ||
+ | {{ftm end}} | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc| | + | {{dsc|[[cpp/numeric/special_functions|'''Mathematical special functions''']]}} |
− | {{dsc see c | c/numeric/math | Common mathematical functions}} | + | {{dsc see c|c/numeric/math|Common mathematical functions|nomono=true}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|tr|zh}} | {{langlinks|cs|de|es|fr|it|ja|pl|pt|ru|tr|zh}} |
Latest revision as of 14:20, 16 September 2023
Contents |
[edit] Functions
Defined in header
<cstdlib> | |
(C++11) |
computes absolute value of an integral value (|x|) (function) |
(C++11) |
computes quotient and remainder of integer division (function) |
Defined in header
<cinttypes> | |
(C++11)(C++11) |
computes absolute value of an integral value (|x|) (function) |
(C++11)(C++11) |
computes quotient and remainder of integer division (function) |
Defined in header
<cmath> | |
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) |
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 one (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 square root of the sum of the squares of two or three(since C++17) given numbers (√x2+y2), (√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) |
[edit] Types
Defined in header
<cstdlib> | |
structure type, returned by std::div (typedef) | |
structure type, returned by std::ldiv (typedef) | |
(C++11) |
structure type, returned by std::lldiv (typedef) |
Defined in header
<cinttypes> | |
(C++11) |
structure type, returned by std::imaxdiv (typedef) |
Defined in header
<cmath> | |
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) |
[edit] Macro constants
Defined in header
<cmath> | |
(C++11)(C++11) |
indicates the overflow value for float, double and long double 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) |
[edit] Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_constexpr_cmath |
202202L | (C++23) | Constexpr for FP environment agnostic mathematical functions in <cmath> and <cstdlib> |
202306L | (C++26) | Constexpr for most mathematical functions in <cmath> |
[edit] See also
Mathematical special functions | |
C documentation for Common mathematical functions
|