class method
Math.cbrt
(::Math::double x) -> ::Float
Math.cbrt(x) → float
math.c
View on GitHub ↗
static VALUE
math_cbrt(VALUE unused_obj, VALUE x)
{
double f = Get_Double(x);
double r = cbrt(f);
#if defined __GLIBC__
if (isfinite(r) && !(f == 0.0 && r == 0.0)) {
r = (2.0 * r + (f / r / r)) / 3.0;
}
#endif
return DBL2NUM(r);
}
Returns the cube root of x.
-
Domain:
[-INFINITY, INFINITY]. -
Range:
[-INFINITY, INFINITY].
Examples:
Example
cbrt(-INFINITY) # => -Infinity cbrt(-27.0) # => -3.0 cbrt(-8.0) # => -2.0 cbrt(-2.0) # => -1.2599210498948732 cbrt(1.0) # => 1.0 cbrt(0.0) # => 0.0 cbrt(1.0) # => 1.0 cbrt(2.0) # => 1.2599210498948732 cbrt(8.0) # => 2.0 cbrt(27.0) # => 3.0 cbrt(INFINITY) # => Infinity