[Rd] R 2.12.1 Windows 32bit and 64bit - are numerical differences expected?
Petr Savicky
savicky at cs.cas.cz
Thu Feb 10 14:33:40 CET 2011
On Thu, Feb 10, 2011 at 10:37:09PM +1100, Graham Williams wrote:
> Should one expect minor numerical differences between 64bit and 32bit R on
> Windows? Hunting around the lists I've not been able to find a definitive
> answer yet. Seems plausible using different precision arithmetic, but waned
> to confirm from those who might know for sure.
One of the sources for the difference between platforms are different
settings of the compiler. On Intel processors, the options may influence,
whether the registers use 80 bit or 64 bit representation of floating
point numbers. In memory, it is always 64 bit. Testing, whether there is
a difference between registers and memory may be done for example using
the code
#include <stdio.h>
#define n 3
int main(int agc, char *argv[])
{
double x[n];
int i;
for (i=0; i<n; i++) {
x[i] = 1.0/(i + 5);
}
for (i=0; i<n; i++) {
if (x[i] != 1.0/(i + 5)) {
printf("difference for %d\n", i);
}
}
return 0;
}
If the compiler uses SSE arithmetic (-mfpmath=sse), then the output is empty.
If Intel's extended arithmetic is used, then we get
difference for 0
difference for 1
difference for 2
On 32 bit Linuxes, the default was Intel's extended arithmetic, while on
64 bit Linuxes, the default is sometimes SSE. I do not know the situation
on Windows.
Another source of difference is different optimization of expressions.
It is sometimes possible to obtain identical results on different platforms,
however, it cannot be generally guaranteed. For tree construction, even
minor differences in rounding may influence comparisons and this may
result in a different form of the tree.
Petr Savicky.
More information about the R-devel
mailing list