Is IEEE-754 arithmetic reproducible across platforms?
I tested code written in R that uses random numbers. I thought setting the seed of a random number generator on all platforms tested would make the tests reproducible, but this is not like the rexp() value that generates exponentially distributed random numbers.
This is what I get on 32-bit Linux:
options(digits=22) ; set.seed(9) ; rexp(1, 5) # [1] 0.2806184054728815824298 sessionInfo() # R version 3.0.2 (2013-09-25) # Platform: i686-pc-linux-gnu (32-bit)
and this is what I get on 64-bit OSX 10.9:
options(digits=22) ; set.seed(9) ; rexp(1, 5) # [1] 0.2806184054728815269186 sessionInfo() # R version 3.0.2 (2013-09-25) # Platform: x86_64-apple-darwin10.8.0 (64-bit)
The 64-bit version of Linux gives the same results as the 64-bit OSX, so this seems like a problem with the 32-bit and 64-bit versions.
Suppose both versions of R were compiled with the same version of GCC and with the same (default R) compilation flags that force the compiler to use IEEE-754 arithmetic.
My question is: can this be considered an error in R? Or is it just a โnormalโ consequence of using approximate floating point arithmetic with finite precision?
I sent the same question to the R-devel mailing list, but did not receive the answer on the list, and only one answer in private, trying to convince me that this is not a mistake, and I have to live with it.
This is what IEEE-754 says about reproducibility (from Wikipedia):
IEEE 754-1985 allows many implementation options (for example, encoding certain values โโand detecting certain exceptions). IEEE 754-2008 tightened many of them, but several options still remain (especially for binary formats). Reproducibility in the article recommends that language standards write reproducible programs (i.e. programs that will result in all implementations of the language) and describes what needs are needed to achieve reproducible results.
And this is in the "Recommendations" section.
My (subjective) opinion is that this is a mistake, because the whole point of the IEEE-754 standard has reproducible, platform-independent floating point arithmetic.