[R] strange behaviour with equality after simple subtraction
bcarvalh at jhsph.edu
Fri Jan 26 18:15:27 CET 2007
In addition to Mike's comment:
> all.equal(x, 1-x)
On Jan 26, 2007, at 11:40 AM, Mike Prager wrote:
> Not at all strange, an expected property of floating-point
> arithmetic and one of the most frequently asked questions here.
>> print(0.1, digits=17)
>  0.1
>> print(1 - 0.9, digits=17)
>  0.09999999999999998
> A simple description of the issue is at
> In most cases, it suffices to test for approximate difference or
> relative difference. The former would look like this
> if (abs(x - x) < eps)) ...
> with "eps" set to something you think is an insignificant
> difference, say 1.0e-10.
> Mike Prager, NOAA, Beaufort, NC
> * Opinions expressed are personal and not represented otherwise.
> * Any use of tradenames does not constitute a NOAA endorsement.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help