[Rd] Rounding error for high-precision numeric values (PR#13010)

hacking at gringer.org hacking at gringer.org
Thu Sep 25 07:00:04 CEST 2008


Full_Name: David Hall (gringer)
Version: 2.7.2 (2008-08-25)
OS: Debian GNU/Linux (sid/lenny)
Submission from: (NULL) (130.195.86.38)


Following on from a conversation I had with someone on IRC about Java's handling
of difficult floating point numbers and its comparison with R's handling, I
observed a couple of values that appeared to have incorrect rounding
(1.9400994884341946e25, 1.9400994884341945e25). R displays these values to 18
significant figures, but the last digit is incorrect (should be 5, displays 4).
This is probably within the realm of "quirky things that we just have to live
with".

Here's how to reproduce the problem:

$ echo -e "options(digits=22)\n1.9400994884341946e25\n1.9400994884341948e25" | R
\
--vanilla

R version 2.7.2 (2008-08-25)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(digits=22)
> 1.9400994884341946e25
[1] 1.940099488434194e+25
> 1.9400994884341948e25
[1] 1.940099488434195e+25
>



More information about the R-devel mailing list