[R] precision in seq

From: Eric Elguero <Eric.Elguero_at_mpl.ird.fr>
Date: Mon, 4 Feb 2008 13:53:52 +0100


Hi everybody,

this is a warning more than a question.

I noticed that seq produces approximate results:

> seq(0,1,0.05)[19]==0.9

[1] TRUE
> seq(0,1,0.05)[20]==0.95

[1] FALSE
> seq(0,1,0.05)[21]==1

[1] TRUE
> seq(0,1,0.05)[20]-0.95

[1] 1.110223024625157e-16

I do not understand why 0.9 and 1 are correct (within some tolerance or strictly exact?) and 0.95 is not.

this one works:

> ((0:20)/20)[20]==0.95

[1] TRUE Eric Elguero



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 04 Feb 2008 - 12:57:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Feb 2008 - 14:00:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive