Re: Math method to calculate root for arbitrary exponent (e.g. cube root)

On 1/29/12, Cameron McCormack <cam@mcc.id.au> wrote:
> Marat Tanalin:
>> It would be nice to have a standard method to calculate arbitrary root
>> (e.g. cube root).
>
> This seems to be a pure ECMAScript enhancement request, so I would
> suggest raising it on the es-discuss mailing list:
>
I agree. I'm not that good at math, but for fun:

function getCubeRoot(x) {
  if(x < 0) {
    return -Math.pow(-x, 1/3);
  }
  return  Math.pow(x, 1/3);
}
-- 
Garrett
Twitter: @xkit
personx.tumblr.com

Received on Monday, 30 January 2012 03:22:27 UTC