Hi, I execute the following code snippet.What I don't understand is, that in the first two cases the numbers shown don't correnspondant to the input (though I have set the options to show 22 digits). When I assign the third number which has one place, the display of the numbers is suddenly correct. Can anybody explain what happens here? (this is just a sample, my real problem lies in numbers that I import from a datafile and I don't know how to control them when this switching occurs) ########################### options( digits=22 ) x <- matrix(NA, 3,1) x[1] <- 6.94788635771657950 x # 6.947886357716580 # DIFFERENT ??? # NA # NA x[1] == 6.94788635771657950 # but is the same x[2] <- 8.34284937565404050 x # 6.947886357716580 # DIFFERENT ??? # 8.342849375654041 # DIFFERENT ??? # NA x[1] == 6.94788635771657950 # but is the same x[3] <- 0.19043842368566377 x # 6.94788635771657950 # NOW OK!!! # 8.34284937565404050 # " " # 0.19043842368566377 # " " x[1] == 6.94788635771657950 # but is the same ### platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.1 year 2006 month 06 day 01 svn rev 38247 language R version.string Version 2.3.1 (2006-06-01) -- Regards, Hans-Peter [[alternative HTML version deleted]]
Hans-Peter <gchappi at gmail.com> writes:> Hi, > > I execute the following code snippet.What I don't understand is, that in the > first two cases the numbers shown don't correnspondant to the input (though > I have set the options to show 22 digits). When I assign the third number > which has one place, the display of the numbers is suddenly correct. > > Can anybody explain what happens here? > (this is just a sample, my real problem lies in numbers that I import from a > datafile and I don't know how to control them when this switching occurs)This looks like it is windows specific: digits=22 is interpreted as 17 or so. On Linux (FC5) I see a few more digits, but I still get an extra decimal in the 3rd case. This is natural since 0.19... needs one more decimal place to be represented to N digit accuracy than does 6.94... and 8.34...> ########################### > options( digits=22 ) > x <- matrix(NA, 3,1) > x[1] <- 6.94788635771657950 > x # 6.947886357716580 # DIFFERENT ??? > # NA > # NA > x[1] == 6.94788635771657950 # but is the same > > x[2] <- 8.34284937565404050 > x # 6.947886357716580 # DIFFERENT ??? > # 8.342849375654041 # DIFFERENT ??? > # NA > x[1] == 6.94788635771657950 # but is the same > > x[3] <- 0.19043842368566377 > x # 6.94788635771657950 # NOW OK!!! > # 8.34284937565404050 # " " > # 0.19043842368566377 # " " > x[1] == 6.94788635771657950 # but is the same > > > ### > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 3.1 > year 2006 > month 06 > day 01 > svn rev 38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > -- > Regards, > Hans-Peter > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- 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 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Mon, 19 Jun 2006, Hans-Peter wrote:> Hi, > > I execute the following code snippet.What I don't understand is, that in the > first two cases the numbers shown don't correnspondant to the input (though > I have set the options to show 22 digits). When I assign the third number > which has one place, the display of the numbers is suddenly correct. > > Can anybody explain what happens here?The problem is that you have set the options to show 22 digits, but the numbers are stored to fewer than 16 digits> .Machine$double.eps[1] 2.220446049250313080847e-16 Everything displayed after the 16th digit is effectively random (the actual values probably depend on exactly when the numbers are loaded into the 80-bit floating point registers on the CPU). The actual results will vary from system to system (on my Linux system the output of x is the same at all stages, and is different from what you report), but nothing beyond the sixteenth digit is at all meaningful. -thomas> (this is just a sample, my real problem lies in numbers that I import from a > datafile and I don't know how to control them when this switching occurs) > > ########################### > options( digits=22 ) > x <- matrix(NA, 3,1) > x[1] <- 6.94788635771657950 > x # 6.947886357716580 # DIFFERENT ??? > # NA > # NA > x[1] == 6.94788635771657950 # but is the same > > x[2] <- 8.34284937565404050 > x # 6.947886357716580 # DIFFERENT ??? > # 8.342849375654041 # DIFFERENT ??? > # NA > x[1] == 6.94788635771657950 # but is the same > > x[3] <- 0.19043842368566377 > x # 6.94788635771657950 # NOW OK!!! > # 8.34284937565404050 # " " > # 0.19043842368566377 # " " > x[1] == 6.94788635771657950 # but is the same > > > ### > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 3.1 > year 2006 > month 06 > day 01 > svn rev 38247 > language R > version.string Version 2.3.1 (2006-06-01) > > > -- > Regards, > Hans-Peter > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle