On Tue, 3 Jun 2003 09:49:44 +0100, you wrote in message <[EMAIL PROTECTED]>:
>Duncan >If the numbers are not represently exactly how does R resolve problems like >the one below? Is there something that needs to be set up in the R >environment like the number of significant figures? > >> x<-4.145*100+0.5 >> x >[1] 415 >> floor(x) >[1] 414 R doesn't do anything to resolve this problem; it's just the way the IEEE standard floating point formats work. In Excel 97, 4.145*100+0.5 is exactly equal to 415; I would guess this is either because they use a binary coded decimal format instead of the IEEE floating point types, or they round results internally in some way. R doesn't support BCD formats, and doesn't do tricky rounding behind your back. You get what you ask for. If you want the calculation above to give you exactly 415, the standard workaround in languages without BCD formats is to work in some decimal multiple of the actual numbers you're interested in, e.g. 10000. Then you would store 4.145 as 41450, multiply by 1000000 (i.e. 100*10000) and divide by 10000 to give 4145000, and add 5000, to give 4150000. All of these numbers are exactly representable in double precision floating point types, because they are all integers with fewer than 53 bits in their binary representations. Doing this means you need to change the definitions of *, /, ^, and lots of other low level functions, but + and - work in the usual way. It might be an interesting project to write a package that does all of this. Duncan Murdoch ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
