MathLib.cbrt()

MathLib.cbrt calculates the cube root of a number: \[ \text{MathLib.cbrt}(x) = \sqrt[3]{x} \]

Examples

To calculate the cube root of 27 type: var result = MathLib.cbrt(27); // result is now 3

Specification

MathLib.cbrt accepts one argument. Any additional arguments will be ignored. The type of the argument should be number. For other argument types see the unary function specification.
  1. MathLib.cbrt(NaN) = NaN
  2. MathLib.cbrt(+0) = +0
  3. MathLib.cbrt(-0) = -0
  4. MathLib.cbrt(+∞) = +∞
  5. MathLib.cbrt(-∞) = -∞
  6. otherwise MathLib.cbrt(x) = cube root of x

Implementation

After handling the special cases, MathLib uses MathLib.sgn(x) * Math.pow(Math.abs(x), 1/3); to get a good approximation. Then it uses Halley's method to improve the approximation.

Tests

Categories: unary Function