[R] Odp: precision issue?
marc_schwartz at me.com
Thu Mar 4 14:38:23 CET 2010
On Mar 4, 2010, at 4:50 AM, Petr PIKAL wrote:
> r-help-bounces at r-project.org napsal dne 04.03.2010 10:36:43:
>> Hi R Gurus,
>> I am trying to figure out what is going on here.
>>> a <- 68.08
>>> b <- a-1.55
>>  1.55
>>> a-b == 1.55
>>  FALSE
>>> round(a-b,2) == 1.55
>>  TRUE
>>> round(a-b,15) == 1.55
>>  FALSE
>> Why should (a - b) == 1.55 fail when in fact b has been defined to be a
> - 1.
>> 55? Is this a precision issue? How do i correct this?
> In real world those definitions of b are the same but not in computer
> world. See FAQ 7.31
> Use either rounding or all.equal.
>> all.equal(a-b, 1.55)
>  TRUE
> To all, this is quite common question and it is documented in FAQs.
> However there is no such issue in Excel or some other spreadsheet
> programs, therefore maybe a confusion from novices.
Actually, there are floating point issues in Excel. Search the archives using "Excel rounding" and you will see discussions dating back to circa 2003 on this, which also reference the differences in OO.org's Calc and Gnumeric's handling of floats.
More information about the R-help