[R] floating point question

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Jan 31 20:56:05 CET 2003

```Deepayan Sarkar <deepayan at stat.wisc.edu> writes:

> Might have something to do with .Machine\$double.eps on the respective
> machines.
>
> From help(.Machine),
>
> double.eps: the smallest positive floating-point number `x' such that
>           `1 + x != 1'.  It equals `base^ulp.digits' if either `base'
>           is 2 or `rounding' is 0;  otherwise, it is `(base^ulp.digits)
>           / 2'.

No, it's trickier than that. I think it's due to the guard digits that
intel FPUs use. Both intel and Sun have 53bit mantissas in double pr.
but intel stores intermediate results to 64 bit precision, so you get
some double rounding effects. Essentially, during alignment, before
adding to 1, 2^-53(1+2^-52) is getting rounded up to binary

0.0000....0001 (52 bits after the ".")

on Sun but down to

0.0000....0000100000000000 (63 bits)

on intel. Then, after adding 1, upon storing it you get the rounding
downwards to

1.0000....0000

>
> On Friday 31 January 2003 01:14 pm, Bob Gray wrote:
> > Does anyone know precisely what is different about the arithmetic
> > and/or storage of double precision floating point to produce the
> > following differences between the Sun and Windows versions (Splus 6
> > on the same Windows 2000 machine gives the same results as Solaris)?
> >
> > R 1.6.1, Sun Solaris, gcc + an old Sun f77
> >
> > > options(digits=20)
> > > 1+(1/2^53+1/2^106)
> >
> > [1] 1
> >
> > > 1+(1/2^53+1/2^105)
> >
> > [1] 1.0000000000000002
> >
> > > 1+(1/2^53+1/2^64)
> >
> > [1] 1.0000000000000002
> >
> > > 1+(1/2^53+1/2^63)
> >
> > [1] 1.0000000000000002
> >
> >
> > > options(digits=20)
> > > 1+(1/2^53+1/2^106)
> >
> > [1] 1
> >
> > > 1+(1/2^53+1/2^105)
> >
> > [1] 1
> >
> > > 1+(1/2^53+1/2^64)
> >
> > [1] 1
> >
> > > 1+(1/2^53+1/2^63)
> >
> > [1] 1.0000000000000002
> >
> > (This may be frivolous, but I have been using the first 2 lines as an
> > example in a course.)
> >
> > Thanks
> > --
> > Bob Gray
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

```