Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Functions | ||||||||||||||||
Basic operations | ||||||||||||||||
| ||||||||||||||||
Exponential functions | ||||||||||||||||
Power functions | ||||||||||||||||
| ||||||||||||||||
Trigonometric and hyperbolic functions | ||||||||||||||||
Error and gamma functions | ||||||||||||||||
Nearest integer floating point operations | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
Floating point manipulation functions | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
Classification and comparison | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
Types | |||||||||||||||||||||||||||||||||||||||||
Macro constants | |||||||||||||||||||||||||||||||||||||||||
|
|
Defined in header <cmath> | ||
(1) | ||
float cbrt(float num); double cbrt(double num); | (until C++23) | |
/*floating-point-type*/ cbrt(/*floating-point-type*/ num); | (since C++23) (constexpr since C++26) | |
float cbrtf(float num); | (2) | (since C++11) (constexpr since C++26) |
longdouble cbrtl(longdouble num); | (3) | (since C++11) (constexpr since C++26) |
SIMD overload(since C++26) | ||
Defined in header <simd> | ||
template</*math-floating-point*/ V> constexpr/*deduced-simd-t*/<V> | (S) | (since C++26) |
Additional overloads(since C++11) | ||
Defined in header <cmath> | ||
template<class Integer> double cbrt( Integer num); | (A) | (constexpr since C++26) |
std::cbrt
for all cv-unqualified floating-point types as the type of the parameter.(since C++23)S) The SIMD overload performs an element-wise std::cbrt onv_num.
| (since C++26) |
A) Additional overloads are provided for all integer types, which are treated asdouble. | (since C++11) |
Contents |
num | - | floating-point or integer value |
If no errors occur, the cube root ofnum (\(\small{\sqrt[3]{num} }\)3√num), is returned.
If a range error occurs due to underflow, the correct result (after rounding) is returned.
Errors are reported as specified inmath_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
1 |
3 |
The additional overloads are not required to be provided exactly as(A). They only need to be sufficient to ensure that for their argumentnum of integer type,std::cbrt(num) has the same effect asstd::cbrt(static_cast<double>(num)).
#include <cmath>#include <iomanip>#include <iostream>#include <limits> int main(){std::cout<<"Normal use:\n"<<"cbrt(729) = "<< std::cbrt(729)<<'\n'<<"cbrt(-0.125) = "<< std::cbrt(-0.125)<<'\n'<<"Special values:\n"<<"cbrt(-0) = "<< std::cbrt(-0.0)<<'\n'<<"cbrt(+inf) = "<< std::cbrt(INFINITY)<<'\n'<<"Accuracy and comparison with `pow`:\n"<<std::setprecision(std::numeric_limits<double>::max_digits10)<<"cbrt(343) = "<< std::cbrt(343)<<'\n'<<"pow(343,1.0/3) = "<<std::pow(343,1.0/3)<<'\n'<<"cbrt(-343) = "<< std::cbrt(-343)<<'\n'<<"pow(-343,1.0/3) = "<<std::pow(-343,1.0/3)<<'\n';}
Possible output:
Normal use:cbrt(729) = 9cbrt(-0.125) = -0.5Special values:cbrt(-0) = -0cbrt(+inf) = infAccuracy and comparison with `pow`:cbrt(343) = 7pow(343,1.0/3) = 6.9999999999999991cbrt(-343) = -7pow(-343,1.0/3) = -nan
(C++11)(C++11) | raises a number to the given power (\(\small{x^y}\)xy) (function)[edit] |
(C++11)(C++11) | computes square root (\(\small{\sqrt{x}}\)√x) (function)[edit] |
(C++11)(C++11)(C++11) | computes hypotenuse\(\scriptsize{\sqrt{x^2+y^2}}\)√x2 +y2 and\(\scriptsize{\sqrt{x^2+y^2+z^2}}\)√x2 +y2 +z2 (since C++17) (function)[edit] |
C documentation forcbrt |