Open
Description
Related to #150 (non-special mathematical functions)
cbrt
- Cube root of a real number
Description
Returns the cube root of the real number (x), that is a number (y) such that (y^3 = x).
Syntax
y = cbrt(x)
Arguments
x
: A real number (x).
Return value
Returns the value (\sqrt[3]{x}), the result is of the type real
and has the same kind as x
.
Example
program demo_cbrt
use stdlib_experimental_math, only: cbrt
print *, cbrt(27.), cbrt(-27.) ! outputs 3, -3
end program
As seen from the discussion on Discourse this function is semantically more accurate than writing x**(1./3.)
which only works for positive real numbers and returns NaN otherwise.
A possible extension would be to allow complex arguments, the return value would then be an array with 3 elements for the 3 cube roots (if the number is real and non-zero, there is one real root and a conjugate pair of complex roots; a complex non-zero value will have three distinct cube roots)