Here is another version of the same idea as Kamil Kiełczewski code but adopted to use big.js API and relies on its implementation details.

function isZero(v) {
    let digits = v.c;
    return digits.length === 1 && digits[0] === 0;
}

function isInteger(v) {
    if (isZero(v))
        return true;
    return v.c.length <= v.e + 1;
}

function neg(v) {
    return new Big(0).minus(v);
}


function cubeRoot(v) {
    const ZERO = Big(0);
    const TEN = new Big(10);

    let c0 = v.cmp(ZERO);
    if (c0 === 0)
        return ZERO;
    if (c0 < 0) {
        let abs3 = cubeRoot(v.abs());
        if (abs3 instanceof Big)
            return neg(abs3);
        else
            return abs3;
    }

    if (!isInteger(v))
        return false;

    // use 10 because it should be fast given the way the value is stored inside Big
    let left = TEN.pow(Math.floor(v.e / 3));
    if (left.pow(3).eq(v))
        return left;

    let right = left.times(TEN);

    while (true) {
        let middle = left.plus(right).div(2);
        if (!isInteger(middle)) {
            middle = middle.round(0, 0); // round down
        }
        if (middle.eq(left))
            return false;
        let m3 = middle.pow(3);
        let cmp = m3.cmp(v);
        if (cmp === 0)
            return middle;
        if (cmp < 0)
            left = middle;
        else
            right = middle;
    }
}

The main idea behind this code is to use binary search but the search starts with a bit better estimate of left and right than in Kamil's code. Particularly, it relies on the fact that Big stores the value in a normalized exponential notation: as an array of decimal digits and exponent. So we can easily find such n that 10^n <= cubeRoot(value) < 10^(n+1). This trick should reduce a few iterations of the loop. Potentially using Newton-Raphson iteration instead of a simple binary search might be a bit faster but I don't think in practice you can see the difference.

Answer from SergGr on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › cbrt
Math.cbrt() - JavaScript | MDN
The Math.cbrt() static method returns the cube root of a number. That is · 𝙼𝚊𝚝𝚑.𝚌𝚋𝚛𝚝 · ( 𝚡 · ) = x · 3 · = the unique · y · such that · y · 3 · = x · \mathtt{\operatorname{Math.cbrt}(x)} = \sqrt[3]{x} = \text{the unique } y \text{ such that } y^3 = x · ...
Top answer
1 of 6
3

Here is another version of the same idea as Kamil Kiełczewski code but adopted to use big.js API and relies on its implementation details.

function isZero(v) {
    let digits = v.c;
    return digits.length === 1 && digits[0] === 0;
}

function isInteger(v) {
    if (isZero(v))
        return true;
    return v.c.length <= v.e + 1;
}

function neg(v) {
    return new Big(0).minus(v);
}


function cubeRoot(v) {
    const ZERO = Big(0);
    const TEN = new Big(10);

    let c0 = v.cmp(ZERO);
    if (c0 === 0)
        return ZERO;
    if (c0 < 0) {
        let abs3 = cubeRoot(v.abs());
        if (abs3 instanceof Big)
            return neg(abs3);
        else
            return abs3;
    }

    if (!isInteger(v))
        return false;

    // use 10 because it should be fast given the way the value is stored inside Big
    let left = TEN.pow(Math.floor(v.e / 3));
    if (left.pow(3).eq(v))
        return left;

    let right = left.times(TEN);

    while (true) {
        let middle = left.plus(right).div(2);
        if (!isInteger(middle)) {
            middle = middle.round(0, 0); // round down
        }
        if (middle.eq(left))
            return false;
        let m3 = middle.pow(3);
        let cmp = m3.cmp(v);
        if (cmp === 0)
            return middle;
        if (cmp < 0)
            left = middle;
        else
            right = middle;
    }
}

The main idea behind this code is to use binary search but the search starts with a bit better estimate of left and right than in Kamil's code. Particularly, it relies on the fact that Big stores the value in a normalized exponential notation: as an array of decimal digits and exponent. So we can easily find such n that 10^n <= cubeRoot(value) < 10^(n+1). This trick should reduce a few iterations of the loop. Potentially using Newton-Raphson iteration instead of a simple binary search might be a bit faster but I don't think in practice you can see the difference.

2 of 6
3

So lets look at some cubes in binary

2^3 = 8 = 100b (3 binary digits)
4^3 = 64 = 100 000b  (6 binary digits)
8^3 = 512 = 100 000 000b (9 binary digits)
(2^n)^3 = 2^(3n) = (3n binary digits).

So for a rough first guess count the number of binary digits, d say, and divide by three, let n = d/3 this tells us if the cube root number is between 2^n and 2^(n+1). Counting digits can be linked to a primitive first approximation to the logarithm.

If you cannot access the binary digits just repeatedly divide by 8 (or a power of 8) until you get a zero result.

Now we can use Newton-Raphson to home into the solution. Wikipedia cube root helpfully gives us the iteration formula. If a is the number we want to find the root of and x_0 is our first guess using the above

x_{n+1} = ( a / x_n^2 + 2 x_n ) / 3.

This can converge really quickly. For example with a=12345678901234567890 we find that a is between 8^21 and 8^22, hence the cube root must be between 2^21 and 2^22.

Running the iteration

x_1 = 2333795, x_1^3 = 12711245751310434875 
x_2 = 2311422, x_2^3 = 12349168818517523448
x_3 = 2311204, x_3^3 = 12345675040784217664
x_4 = 2311204, x_4^3 = 12345675040784217664

and we see it has converged after three iterations. Checking shows that a is between 2311204^3 and 2311205^3.

This algorithm can run with calculations using big.js. The above calculations have been done using Java's BigInt class.

🌐
W3Schools
w3schools.com › jsref › jsref_cbrt.asp
JavaScript Math cbrt() Method
The Math.cbrt() method returns the cubic root of a number. The Math.sqrt() Method The Math.SQRT2 Property The Math.SQRT1_2 Property ... Math.cbrt() is an ECMAScript6 (ES6 2015) feature. JavaScript 2015 is supported in all browsers since June 2017:
🌐
TutorialsPoint
tutorialspoint.com › how-to-find-the-cube-root-of-a-number-in-javascript
How to find the cube root of a number in JavaScript?
<!DOCTYPE html> <html> <head> <title>To find the cube root of a number in JavaScript</title> </head> <body style="text-align : center"> <h3>To find the cube root of a number in JavaScript</h3> <p id='cbrt'></p> <script> let a = Math.cbrt(36, 1/3); let b = Math.cbrt(125,1/3); let c = Math.cbrt(-36.1/3); let d = Math.cbrt(-125,1/3); document.getElementById('cbrt').innerHTML = `The cube root value for 36 is ${a} ${'<br/>'} The cube root value for 125 is ${b} ${'<br/>'} The cube root value for -36 is ${c} ${'<br/>'} The cube root value for -125 is ${d} ${'<br/>'}`; </script> </body> </html>
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › cbrt
JavaScript Math cbrt() - Compute Cube Root | Vultr Docs
November 29, 2024 - The Math.cbrt() method in JavaScript calculates the cube root of a given number. It is a part of the extensive Math object, which provides utilities for performing complex mathematical operations conveniently.
🌐
Programiz
programiz.com › javascript › library › math › cbrt
JavaScript Math cbrt() (with Examples)
In this tutorial, you will learn about the JavaScript Math.cbrt() method with the help of examples. The JavaScript Math.cbrt() method computes the cube root of a specified number and returns it.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-math-cbrt-function
JavaScript Math cbrt() Function | GeeksforGeeks
December 30, 2022 - The Javascript Math.cbrt() function is used to find the cube root of a number.
🌐
Math.js
mathjs.org › docs › reference › functions › cbrt.html
math.js | an extensive math library for JavaScript and Node.js
Calculate the cubic root of a value. To avoid confusion with the matrix cube root, this function does not apply to matrices.
🌐
TechOnTheNet
techonthenet.com › js › math_cbrt.php
JavaScript: Math cbrt() function
This JavaScript tutorial explains how to use the math function called cbrt() with syntax and examples. In JavaScript, cbrt() is a function that is used to return the cube root of a number.
Find elsewhere
🌐
Tutorial Gateway
tutorialgateway.org › javascript-cbrt
JavaScript cbrt Function
March 23, 2025 - The JavaScript cbrt function is one of the Math functions, and it is used to find the cube root of a specified expression or an individual number.
🌐
FlatCoding
flatcoding.com › home › math.cbrt in javascript: how to finds cube roots
Math.cbrt in JavaScript: How to Finds Cube Roots - FlatCoding
June 26, 2025 - This keeps the result accurate. Math.cbrt returns the cube root of any number. A cube root is a value that, when multiplied by itself three times, gives the original number. The function works with integers and floats.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-find-cube-root-of-a-number
JavaScript Program to Find Cube Root of a Number - GeeksforGeeks
August 5, 2025 - JavaScript's 'Math.pow' method can be used to directly compute the cube root by raising the number to the power of 1/3.
🌐
GoLinuxCloud
golinuxcloud.com › home › javascript › javascript math.cbrt() examples [in-depth tutorial]
JavaScript Math.cbrt() Examples [In-Depth Tutorial] | GoLinuxCloud
February 19, 2023 - The Math.cbrt() function is a built-in JavaScript method that allows you to find the cube root of a number. It takes a single argument, which is the number
🌐
Javatpoint
javatpoint.com › javascript-math-cbrt-method
JavaScript Math cbrt() Method - javatpoint
JavaScript Math cbrt() Method with example, javascript math methods, abs() method, round() method, ceil() method, floor() method, pow() method, random() method, sqrt() method, max() method, min() method, log() method, sin() method, cos() method, tan() method etc.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-math-exercise-92.php
JavaScript - Iterated Cube Root
/** * Function to calculate the number of iterations required to find the cube root of a number greater than or equal to 3. * @param {number} n - The number for which cube root iterations are to be performed. * @returns {number|string} - The number of iterations required to find the cube root, or a string indicating that the input is not a positive number.
🌐
TutorialsPoint
tutorialspoint.com › javascript › math_cbrt.htm
JavaScript Math.cbrt() Method
In general, the cube root of a ... of a number (x) is a value (y) such that yyy = x. The JavaScript Math.cbrt() method accepts a number as a parameter and calculates the cuberoot of a provided number....
🌐
W3Schools
w3schools.com › js › tryit.asp
JavaScript Math.cbrt()
The W3Schools online code editor allows you to edit code and view the result in your browser