std::cbrt

From cppreference.com
< cpp‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)
(C++11)
(C++11)
Power functions
cbrt
(C++11)
(C++11)
Trigonometric and hyperbolic functions
(C++11)
(C++11)
(C++11)
Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
Classification/Comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)(C++11)(C++11)(C++11)(C++11)
 
Defined in header <cmath>
float       cbrt( float arg );
(1) (since C++11)
double      cbrt( double arg );
(2) (since C++11)
long double cbrt( long double arg );
(3) (since C++11)
double      cbrt( Integral arg );
(4) (since C++11)

Computes the cubic root of arg.

4) A set of overloads or a function template accepting an argument of any integral type. Equivalent to 2) (the argument is cast to double).

Contents

[edit] Parameters

arg - value of a floating-point or Integral type

[edit] Return value

If no errors occur, the cubic root of arg (3arg), is returned.

If a range error occurs due to underflow, the correct result (after rounding) is returned.

[edit] Error handling

Errors are reported as specified in math_errhandling

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

  • if the argument is ±0 or ±∞, it is returned, unchanged
  • if the argument is NaN, NaN is returned.

[edit] Notes

std::cbrt(arg) is not equivalent to std::pow(arg, 1.0/3) because std::pow cannot raise a negative base to a fractional exponent.

[edit] Example

#include <iostream>
#include <cmath>
 
int main()
{
    // normal use
    std::cout << "cbrt(729) = " << std::cbrt(729) << '\n'
              << "cbrt(-0.125) = " << std::cbrt(-0.125) << '\n';
    // special values
    std::cout << "cbrt(-0) = " << std::cbrt(-0.0) << '\n'
              << "cbrt(+inf) = " << std::cbrt(INFINITY) << '\n';
}

Output:

cbrt(729) = 9
cbrt(-0.125) = -0.5
cbrt(-0) = -0
cbrt(+inf) = inf

[edit] See also

raises a number to the given power (xy)
(function)
computes square root (x)
(function)
(C++11)
computes square root of the sum of the squares of two given numbers (x2
+y2
)
(function)
C documentation for cbrt