On Nov 30, 2013, at 8:54, 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. Yes, if they do the same operations. But that's a big if. Beyond general 'compiler magic' you'll also want to look at the matrix multiplication libraries used. Cheers, Michael > > 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 _______________________________________________ R-SIG-Mac mailing list R-SIG-Mac@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac