Message-ID: <9C40CDA6-C110-4B3A-B108-5A6478E3F9CE@xs4all.nl>
Date: 2012-11-29T07:32:34Z
From: Berend Hasselman
Subject: Ceiling function gives me wrong answer
In-Reply-To: <CALcChFQ=HAUi3_ktAP5h-pzrvnYubJ1SmVLjKi44x82aHcnw1Q@mail.gmail.com>
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