4 ms·
>> because floats - or numerical methods in general - are simply not meant to be used for exact results But one should expect a single function does not vary i
by phkahler 6y ago
>> because floats - or numerical methods in general - are simply not meant to be used for exact results
But one should expect a single function does not vary in the last 5 digits as one example did. That's over 16 bits. Why should anyone use double precision if that's the kind of slop an implementation can have?
- hansvm 6y ago> But one should expect a single function does not vary in the last 5 digits as one example did. Why not? The whole selling point of floats is that they're a fast approximation to real arithmetic in a bunch of useful cases. I'd personally be much more miffed by an excessively slow implementation of a transcendental than one which was off even by a large number of bits. If there's a fast solution with better precision then that's great, but low precision by itself doesn't strike me as particularly problematic. > Why should anyone use double precision if that's the kind of slop an implementation can have? Because by using float64 instead of float32 you can cheaply get a ton more precision even with sloppy algorithms. If there's only 16ish bits of slop you could probably get a full-precision float32 operation just by using an intermediate cast to float64 (proof needed for the algorithm in question of course).
- topspin 6y ago> But one should expect a single function does not vary in the last 5 digits as one example did. That's over 16 bits. 0.9999999999999999999999999999999 1.0000000000000000000000000000000 Counting the number of different digits has no useful meaning. The example you cite has two results that differ by 1 part in 10 quadrillion. If you have a good reason care about the precise implementation of hyperbolic functions to that level of precision then you don't rely on whatever you happen to stumble on in some version of nodejs.
- lern_too_spel 6y agoIf you're talking about the tanh example, that differs in the last five bits of the mantissa. You don't want to count the number of different bits because differences in the more significant bits are worse. Count the ulps instead.