[R] bug?
M. Edward Borasky
znmeb at aracnet.com
Mon Jul 14 15:02:49 CEST 2003
To be more precise, the decimal number 0.1 does not have an exact binary
equivalent. A long time ago, there was a book called, IIRC, "Pascal with
Style" or something of that ilk, which set out the warning "Never compare
floating point numbers for equality."
--
M. Edward (Ed) Borasky
mailto:znmeb at borasky-research.net
http://www.borasky-research.net
"Suppose that tonight, while you sleep, a miracle happens - you wake up
tomorrow with what you have longed for! How will you discover that a miracle
happened? How will your loved ones? What will be different? What will you
notice? What do you need to explode into tomorrow with grace, power, love,
passion and confidence?" -- L. Michael Hall, PhD
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Uwe Ligges
> Sent: Monday, July 14, 2003 1:10 AM
> To: Marc Vandemeulebroecke
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] bug?
>
>
> Marc Vandemeulebroecke wrote:
>
> > Dear R programmers,
> >
> > is there a sensible explanation for the following behaviour? The
> > second command seems not to be interpreted correctly.
> >
> >
> >>seq(0.6, 0.9, by=0.1) == 0.8
> >
> > [1] FALSE FALSE TRUE FALSE
> >
> >>seq(0.7, 0.9, by=0.1) == 0.8
> >
> > [1] FALSE FALSE FALSE
> >
> >>c(0.7, 0.8, 0.9) == 0.8
> >
> > [1] FALSE TRUE FALSE
> >
> >>seq(0.9, 0.7, by=-0.1) == 0.8
> >
> > [1] FALSE TRUE FALSE
> >
> > I am running R version 1.7.1 on XP and NT.
> >
> > Thanks,
> > Marc
> >
> > --
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
> It is correct, just an instability of the representation of that
> floating point number, because (regularly) floating point
> numbers cannot
> be represented exactly.
>
> Uwe Ligges
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>
More information about the R-help
mailing list