Skip to content
Back to formatted view

Raw Message

Message-ID: <OF839E7345.7D916AD3-ONC12576A4.0048B084-C12576A4.0048E0DB@precheza.cz>
Date: 2010-01-07T13:15:33Z
From: PIKAL Petr
Subject: Odp:  Strange behaviour of as.integer()
In-Reply-To: <1262867502.7279.1.camel@EMACS-Keller>

Hi

Maybe FAQ 7.31 strikes again.

> .57 * 100==as.integer(57)
[1] FALSE
>

Regards
Petr


r-help-bounces at r-project.org napsal dne 07.01.2010 13:31:42:

> I have encountered a strange behaviour of as.integer() which does not
> seem correct to me. Sorry if this is just an indication of me not
> understanding floating point arithmetic.
> 
> > .57 * 100
> [1] 57
> > .29 * 100
> [1] 29
> 
> So far, so good. But:
> 
> > as.integer(.57 * 100)
> [1] 56
> > as.integer(.29 * 100)
> [1] 28
> 
> Then again:
> 
> > all.equal(.57 * 100, as.integer(57))
> [1] TRUE
> > all.equal(.29 * 100, as.integer(29))
> [1] TRUE
> 
> This behaviour is the same in R 2.10.1 (Ubuntu and Windows) and 2.9.2
> (Windows),
> all 32 bit versions. Is this really intended?
> 
> ______________________________________________
> 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.