[Rd] round() doesn't (PR#1139)
Tue, 23 Oct 2001 01:15:39 +0200 (MET DST)
R> round(100000/3, -2) - 33300
I would have hoped for 0. The problem seems to be specifically for negative
"digits". This is in 1.3.1 on Solaris 2.6 (full description at bottom).
[Apologies for making everyone read this 3 times; my bug.report() burped.]
Peter Dalgaard <email@example.com> says the problem is in fround.c,
which reads in part:
pow10 = R_pow_di(10., dig)
return sgn * (intx + R_rint(x * pow10) / pow10);
and (says Peter),
> the problem is most likely that pow10 (== 1/100) has no finite binary
> representation. Patches are welcome...
I'm not up to patching C code, but I will say that a workaround is:
R> round(round(100000/3, -2)) - 33300
and a smarter C-programmer could probably implement this concept:
if digits < 0, force the final result to an integer.
-- David Brahm (firstname.lastname@example.org)
platform = sparc-sun-solaris2.6
arch = sparc
os = solaris2.6
system = sparc, solaris2.6
major = 1
minor = 3.0
year = 2001
month = 06
day = 22
language = R
.GlobalEnv, package:misc, package:io, package:arrays, package:ls1, package:db, package:ts, package:ctest, Autoloads, package:base
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: email@example.com