[R] Interesting quirk with fractions and rounding / using == for floating point
pdalgd at gmail.com
Sun Apr 23 15:37:09 CEST 2017
> On 23 Apr 2017, at 14:49 , J C Nash <profjcnash at gmail.com> wrote:
> So equality in floating point is not always "wrong", though it should be used
> with some attention to what is going on.
> Apologies to those (e.g., Peter D.) who have heard this all before. I suspect
> there are many to whom it is new.
Peter D. still insists on never trusting exact equality, though. There was at least one case in the R sources where age-old code got itself into a condition where a residual terme that provably should decrease on every iteration oscillated between two values of 1-2 ulp in magnitude without ever reaching 0. The main thing is that you cannot trust optimising compilers these days. There is, e.g., no guarantee that a compiler will not transform
(x_new + offset) == (x_old + offset)
(x_new + offset) - (x_old + offset) == 0
(x_new - x_old) + (offset - offset) == 0
to.... well, you get the point.
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Office: A 4.23
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help