Is there any way to guarantee the results of cross-platform regression tests for the floating point calculation?
Is there any way to guarantee the results of cross-platform regression tests for the floating point calculation?
For example, different implementations may return different results when converting the same binary value to decimal, such described as i开发者_运维技巧n: http://code.google.com/p/mochiweb/issues/detail?id=59
I am interested in Erlang/OTP cases, but examples in other languages and environments are welcome.
Erlang relies on the underlying systems floating point implementation.
Floating point behaviour testing is pretty hard. Probably the most known test for platform floating point behaviour was written by William Kahan and is called paranoia
.
It was ported to some languages and even a version for GPU's.
This is however only testing the basic floating point behaviour of platforms.
What you are referencing is diverse C library behaviour of strtod
between platforms.
This might be be tested by C standard conformance testing software.
But tests are no guarantee so what you are asking for is not achievable. There will always be subtle bugs or differences in floating point software and even CPU's
Best is to validate the results of your calculations and write tests of your floating point using modules.
In principle, if we look at C (which is used under the hood for Erlang), primitive operations like multiplication, casting et.c. should be consistent across environments. Functions from the standard library, on the other hand, might not.
Note that some compilers, including gcc, by default cheat a little bit, but provides a command-line option to comply to rules.
精彩评论