[R-SIG-Mac] Inaccurate inaccuracies on Mac only?

Simon Urbanek simon.urbanek at r-project.org
Tue Dec 3 02:48:17 CET 2013


On Dec 2, 2013, at 8:35 PM, Kasper Daniel Hansen <kasperdanielhansen at gmail.com> wrote:

> I don't think your assumption that different systems will return the same (accurate or inaccurate) answers is correct.  I don't even think you can assume that running the same code twice on the same system will give you the same answers, although in practice it often will.
> 

That is true, but it does indeed depend on the code. For example 2L - 1L will always yield the same result, not matter how often you run it.

But more to the point, IEEE just guarantees results *assuming* certain precision, but R will use more precision if available for some operations. Now, how much more precision there is available depends on the CPU and architecture, and I suspect that Hans was not sharing enough details. For example, I get the same answer on Ubuntu 12.04 LTS that I get on a Mac contrary to his claims - both with x86_64 architecture (which I suspect is the real difference). And this is not just about R - compilers will often use SIMD instructions instead of FP instructions where it is faster and doesn’t reduce the accuracy - but it may increase it.

Cheers,
Simon


> 
> On Sat, Nov 30, 2013 at 8:54 AM, Hans W Borchers <hwborchers at gmail.com>wrote:
> 
>> Dear R Mac colleagues,
>> 
>> when I am running the following piece of code on Ubuntu Linux 12.04 LTS or
>> on
>> Windows 7 -- with R 3.0.2 --, I get the results as indicated:
>> 
>>    set.seed(8237)
>>    x <- runif(32, -1, 1)
>>    y <- runif(32, -1, 1)
>>    u <- cbind(x[1], y[1])
>> 
>>    u1 <- u %*% t(u)
>>    u2 <- apply(u * u, 1, sum)
>>    sqrt(u2 + u2 - 2*u1)
>>    ##      [,1]
>>    ## [1,]  NaN
>>    ## Warning message:
>>    ##    In sqrt(u2 + u2 - 2 * u1) : NaNs produced
>>    u2 + u2 - 2*u1
>>    ##               [,1]
>>    ## [1,] -2.220446e-16
>> 
>> Theoretically, the last value should be zero. Of course, I am *not*
>> surprised
>> to see this is not the case under finite precision arithmetics.
>> 
>> But what did surprise me was that under Mac OS X 10.6 and R 3.0.2 I get the
>> following, exact results:
>> 
>>    set.seed(8237)
>>    x <- runif(32, -1, 1)
>>    y <- runif(32, -1, 1)
>>    u <- cbind(x[1], y[1])
>> 
>>    u1 <- u %*% t(u)
>>    u2 <- apply(u * u, 1, sum)
>>    sqrt(u2 + u2 - 2*u1)
>>    ##      [,1]
>>    ## [1,]    0
>>    u2 + u2 - 2*u1
>>    ##      [,1]
>>    ## [1,]    0
>> 
>> I always thought that all these systems and versions comply to the IEEE
>> floating point standard and return the same (accurate or inaccurate)
>> answers.
>> 
>> The problem here is: When I test a package on Mac, I cannot be sure it will
>> run without errors on other systems. Actully, I found this when running
>> some
>> examples from help pages, written on the Mac.
>> 
>> Was I wrong, or is there something special about the Mac version of R ?
>> 
>> Many thanks
>> Hans Werner
>> 
>> _______________________________________________
>> R-SIG-Mac mailing list
>> R-SIG-Mac at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> 



More information about the R-SIG-Mac mailing list