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.

Kasper


On Sat, Nov 30, 2013 at 8:54 AM, Hans W Borchers <hwborch...@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@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>

        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to