ES6 accuracy of special functions
carl.shapiro at gmail.com
Mon Jul 28 10:49:15 PDT 2014
In ECMA-262, section 15.8.2
the note allows implementations to choose appropriate algorithms for the
evaluation of the special functions and it is recommended but not required
to use the algorithms from fdlibm <http://netlib.org/fdlibm>.
Since this is a recommendation and not a requirement implementations
compute incorrect results for some values. This produces things where
Math.cos(Math.pow(2,120)) doesn’t even have the correct sign or basic
identities like sin(-x) = -sin(x) don’t hold for all finite values of x.
gives some results from various browsers on some selected functions.
This lack of precision makes it very difficult to port numerical
for correct behaviour. This seems a major disservice to the web platform
Since the specification recommends using the algorithms from fdlibm, which,
I believe produces results that are accurate to < 1 ulp, why not make this
a requirement? As the spreadsheet shows, many browsers already achieve
provided a couple of key routines are available. (My colleague has done
this for the trig functions, except for the hairy case of the Payne-Hanek
pi reduction routine.)
Note also that Java requires that many special function be accurate to < 1
ulp. (See http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html)
on existing implementations. Java is an existence proof that these
requirements can work.
While having an accuracy requirement is good in itself, it’s also important
that the functions are semi-monotonic to match the mathematical functions.
This is also a requirement in Java. It is known that applications using
divided differences behave incorrectly when functions are not monotonic
when they should be.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss