From ripley at stats.ox.ac.uk  Sun Jan 19 08:45:02 2014
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sun, 19 Jan 2014 07:45:02 +0000
Subject: [Rd] rexp, different results on 32/64 bit
In-Reply-To: <CABtg=KmC4GJmACQ=XjFHrJ6jRyrk4ZnscN-TzS0DYgpfkZPPMQ@mail.gmail.com>
References: <CABtg=KmC4GJmACQ=XjFHrJ6jRyrk4ZnscN-TzS0DYgpfkZPPMQ@mail.gmail.com>
Message-ID: <52DB827E.9090506@stats.ox.ac.uk>

On 17/01/2014 18:58, G?bor Cs?rdi wrote:
> Hi all,
>
> I just run into this today. Apparently rexp() sometimes gives different
> slightly results for the same seed on 32 bit and 64 bit machines. runif()
> is the same for both, so the problem seems to be in rexp().

Rather, the 'problem' is in your expectations: different builds of R 
should be expected to give different results.

A better way to look at the fine detail of doubles is

 > sprintf("%a", foo) # 64-bit
[1] "0x1.1f5a6e68a593p-2"
 > sprintf("%a", foo) # 32-bit
[1] "0x1.1f5a6e68a5931p-2"

on my Fedora box.  (Otherwise the difference might well have been in the 
binary to decimal conversion used for printing.)

And for the record: the reasons 32-bit results are often different
include that the lowest common denominator for i686 cpus[*] is lower
than for x86_64 ones. Also, the OS X results quoted most likely are for
the CRAN distribution using a rather old compiler which does not
optimize as well as current ones, and you are comparing different
runtimes (libc), whereas I was comparing i686 and x86_64 compiles on the
same machine, with the same compiler/runtime versions.

[*] And for R for Windows i386 cpus are still supported, alongside 
Windows XP.

>
> 64 bit Linux is the same as 64 bit OSX, and R-devel gives the same results
> as R-3.0.2.
>
> Best,
> Gabor
>
> # ---------------------------------------------
>> options(digits=22) ; set.seed(9) ; rexp(1, 5)
> [1] 0.2806184054728815824298
>> options(digits=22) ; set.seed(9) ; runif(1)
> [1] 0.2216013972647488117218
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: i686-pc-linux-gnu (32-bit)
>
> locale:
>   [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
>   [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8
>   [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8
>   [7] LC_PAPER=en_US.utf8       LC_NAME=C
>   [9] LC_ADDRESS=C              LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> # ---------------------------------------------
>> options(digits=22) ; set.seed(9) ; rexp(1, 5)
> [1] 0.2806184054728815269186
>> options(digits=22) ; set.seed(9) ; runif(1)
> [1] 0.2216013972647488117218
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] rexp, different results on 32/64 bit
Prof Brian Ripley