[EMAIL PROTECTED] writes: > Where is my error?? > I have a strange behaviour in R, looks like type conversions are messed = > up. > Maybe i just make a stupid mistake, but help would be appreciated. > > To reproduce: > > expected: > > typeof(3) > [1] "double" > > > as.integer(3) > [1] 3 > > > typeof((0.3/0.1)) > [1] "double" > > !!!! strange: > > as.integer((0.3/0.1)) > [1] 2 > > also for trunc: > >trunc(c(5,7)) > [1] 5 7 > > >c(0.5,0.7)/c(0.1,0.1) > [1] 5 7 > > and now watch: > >trunc((c(0.5,0.7)/c(0.1,0.1))) > [1] 5 6
None of this is bugs. Please read up on floating point representations on a binary computer. Specifically: > 0.3/0.1 - 3 [1] -4.440892e-16 > 0.7/0.1 - 7 [1] -8.881784e-16 > 0.5/0.1 - 5 [1] 0 > My R-Version: > platform i386-pc-mingw32 > arch i386 =20 > os mingw32 =20 > system i386, mingw32 =20 > status =20 > major 2 =20 > minor 1.1 =20 > year 2005 =20 > month 06 =20 > day 20 =20 > language R > > > Cheers, > Grischa T=F6dt > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel