[R] Inconsistency using seq
Henrik Bengtsson
hb at biostat.ucsf.edu
Tue Jun 19 01:12:20 CEST 2012
FYI,
> isZero <- function(x, neps=1, eps=.Machine$double.eps, ...) {
+ (abs(x) < neps * eps)
+ }
> x <- seq(from=0, to=4, by=0.1)
> isZero(x[4]-0.3)
[1] TRUE
> isZero(x[4]-0.3, neps=1)
[1] TRUE
> isZero(x[4]-0.3, neps=0.1)
[1] FALSE
You could also have called isZero() isValueSmallEnoughForWhatINeed().
My $.02
/Henrik
On Mon, Jun 18, 2012 at 2:29 PM, Bert Gunter <gunter.berton at gene.com> wrote:
> Nope. round() is not failsafe either. Basically, there is theoretically no
> way to guarantee immunity to floating point error in conditional
> comparisons. You need to either switch to integers -- which **are** exactly
> represented -- or figure out another way.
>
> Of course, practically speaking, sufficient rounding will work. It's just
> that it **can** always break. ... and you know Murphy's first law.
>
> -- Bert
>
> On Mon, Jun 18, 2012 at 1:54 PM, hamoreno <hamoreno at asu.edu> wrote:
>
>> Thanks everyone... Seems that I will have to use round before seq to make
>> sure everything has the correct precision.
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Inconsistency-using-seq-tp4633739p4633750.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list