W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

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

From: Marat Tanalin | tanalin.com <mtanalin@yandex.ru>
Date: Mon, 30 Jan 2012 03:48:23 +0400
To: public-script-coord@w3.org
Message-Id: <625731327880903@web93.yandex.ru>
Hello.

It would be nice to have a standard method to calculate arbitrary root (e.g. cube root).

Currently similar result can be achieved with Math.pow(x, 1/n) where x is source number, and n is exponent. But that does not work with negative x and returns NaN in all browsers:

    Math.pow(-8, 1/3) // -2 is expected, NaN is returned.

So probably either Math.pow() should be improved to take negative numbers into account, or a new method like Math.root(x, n) should be added.

While, of course, the issue can be _currently_ worked around with a pure-script solution taking negative numbers into account, this proposal is exactly about improving _core JavaScript functionality_ to provide _standard_ means for the purpose.

Thanks.
Received on Sunday, 29 January 2012 23:49:01 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:05 UTC