3 ms·
> We've been computing these functions for over 60 years electronically (and longer analog), and I guarantee there is an implementation that fits your constrain
by titzer 7y ago
> We've been computing these functions for over 60 years electronically (and longer analog), and I guarantee there is an implementation that fits your constraints.
TLDR; Math keeps changing because Javascript's spec is weak. Users almost always want the most accurate, most stable and most reliable answer by default. It's the principle of least surprise.
While I mostly agree with your comment (and upvoted you), I think the main problem the author runs into is that Javascript's Math library is underspecified in a bad way. The trig functions have precision that is really only held up by Web Reality, meaning the least precision that the bulk of websites can function under before something breaks and someone starts complaining.
I saw this firsthand. I worked on V8 during the time a number of precision-altering changes were made to its implementation of Math.*. Some had to be reverted because websites did indeed misbehave. I could claim it "wasn't our fault" because we were legally allowed to do so according to the spec....but not sure I want to own that ;-)
Compare this to e.g. Java, which specifies that all math functions in its standard library are accurate to 1up. They absolutely should give you bit-accurate results on every implementation.