title: Implementing an accurate cbrt() function without extra precision
body: <p>In JavaScript, there is no native <code>cbrt</code> method available. In theory, you could use a method like this:</p>
  
  <pre><code>function cbrt(x) {
    return Math.pow(x, 1 / 3);
  }
  </code></pre>
  
  <p>However, this fails because identities in mathematics don't necessarily apply to floating point arithmetic. For example, 1/3 cannot be accurately represented using a binary floating point format.</p>
  
  <p>An example of when this fails is the following:</p>
  
  <pre><code>cbrt(Math.pow(4, 3)); // 3.9999999999999996
  </code></pre>
  
  <p>This gets worse as the number gets larger:</p>
  
  <pre><code>cbrt(Math.pow(165140, 3)); // 165139.99999999988
  </code></pre>
  
  <p>Is there any algorithm which is able to calculate a cube root value to within a few ULP (preferably 1  ULP if possible)?</p>
  
  <p>This question is similar to <a href="https://stackoverflow.com/questions/18063755/computing-a-correctly-rounded-an-almost-correctly-rounded-floating-point-cubic">Computing a correctly rounded / an almost correctly rounded floating-point cubic root</a>, but keep in mind that JavaScript doesn't have any higher-precision number types to work with (there is only one number type in JavaScript), nor is there a built-in <code>cbrt</code> function to begin with.</p>