From teck.lim at imperial.ac.uk  Tue May 30 14:43:06 2006
From: teck.lim at imperial.ac.uk (teck.lim at imperial.ac.uk)
Date: Tue, 30 May 2006 14:43:06 +0200 (CEST)
Subject: [Rd] Numerical error in R (win32) (PR#8909)
Message-ID: <20060530124306.C0DBE3F045@slim.kubism.ku.dk>

Hi

	Thanks for the quick reply. However, I am not satisfied, as
> round(3.15000000, 1)
[1] 3.1
> round(3.75000000, 1)
[1] 3.8

	I think the problem is really more of an error in the rounding off
algorithm than finite precision.

Thanks
Teckpor 

-----Original Message-----
From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de] 
Sent: Monday, May 29, 2006 17:45
To: teck.lim at imperial.ac.uk
Cc: R-bugs at biostat.ku.dk
Subject: Re: [Rd] Numerical error in R (win32) (PR#8909)

teck.lim at imperial.ac.uk wrote:

> Hi
>     I had observed the following problem in R (also C, Matlab, and
Python).
> sprintf('%1.2g\n', 3.15)
> give 3.1 instead of 3.2 whereas an input of 3.75 gives 3.8.
> Java's System.out.printf is ok though.  
>  
> 
>>round(3.75,1)
> 
> [1] 3.8
> 
>>round(3.15,1)
> 
> [1] 3.1
>  
> Similar outcome with sprintf in R.
> 
> 
> However, the right answer should be 3.2

This is not a bug.

Please read the R FAQ "Why doesn't R think these numbers are equal?" and
after that note that *numerically* the following inaqualities are TRUE:
(3.2 - 3.15) > 0.05
(3.15 - 3.1) < 0.05

Uwe Ligges


> Regards
> Teckpor
>  
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Numerical error in R (win32) (PR#8909)
teck.lim at imperial.ac.uk