[R] Ceiling function gives me wrong answer
    Berend Hasselman 
    bhh at xs4all.nl
       
    Thu Nov 29 08:32:34 CET 2012
    
    
  
On 29-11-2012, at 03:10, Ying Zheng wrote:
> Hi all,
> 
> I have a very simple code, but gives a wrong answer.
> 
> a=1000
> b=1000^(1/3)
> c=ceiling(a/b)
> 
> then c=101,
> 
> if change the code to be
> a=1000
> b=10
> c=ceiling(a/b)
> 
> then c=100 is fine.
See R FAQ 7.31 "Why doesn't R think these numbers are equal?"
> sprintf("%.17f",1000/10)
[1] "100.00000000000000000"
> sprintf("%.17f",1000/1000^(1/3))
[1] "100.00000000000001421"
Berend
    
    
More information about the R-help
mailing list