I\'m writing a specification that describes some arithmetic that will be performed by software. The intention is that I can hand this spec to two different programmers (who
IEEE 754-2008 clause 11 describes what is necessary for reproducible floating-point results. This is largely:
a*b
performs the floating-point multiplication specified by IEEE 754).These requirements are poorly supported in today’s compilers.
Adding .5 will not be a problem. All normal floating-point implementations represent .5 exactly and add it correctly. What will be a problem is that a language implementation may add .5 and keep the result precisely (more precisely than a usual double
) while another implementation rounds the result to double
. If math library routines are used (such as cos
and log
), that is another problem, because they are hard to compute well, and different implementations provide different approximations.
IEEE 754 is a good specification. Ideally, you would specify that implementations of your specification conform to IEEE 754.