p.murrell@auckland.ac.nz
2003-Oct-13 01:38 UTC
[Rd] zapsmall with all values small (PR#4554)
Hi If all values are small, zapsmall does not zap. For example ... > zapsmall(1e-24) [1] 1e-24 > zapsmall(1e-24, digits=3) [1] 1e-24 Problem appears to be in calculation of digits ... mx <- max(abs(x[!ina])) digits = if (mx > 0) max(0, digits - log10(mx)) else digits If all values are small, mx is very small, log10(mx) is "large" but negative, digits - log10(mx) is very large, so no rounding occurs. Paul --please do not edit the information below-- Version: platform = i686-pc-linux-gnu arch = i686 os = linux-gnu system = i686, linux-gnu status = Under development (unstable) major = 1 minor = 9.0 year = 2003 month = 10 day = 12 language = R Search Path: .GlobalEnv, package:gridBase, package:methods, package:ctest, package:mva, package:modreg, package:nls, package:ts, package:lattice, package:grid, package:graphicsQC, Autoloads, package:base -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
maechler@stat.math.ethz.ch
2003-Oct-13 09:21 UTC
[Rd] zapsmall with all values small (PR#4554)
>>>>> "Paul" == p murrell <p.murrell@auckland.ac.nz> >>>>> on Mon, 13 Oct 2003 01:39:21 +0200 (MET DST) writes:Paul> Hi If all values are small, zapsmall does not zap. Paul> For example ... >> zapsmall(1e-24) Paul> [1] 1e-24 >> zapsmall(1e-24, digits=3) Paul> [1] 1e-24 Paul> Problem appears to be in calculation of digits ... Paul> mx <- max(abs(x[!ina])) digits = if (mx > 0) Paul> max(0, digits - log10(mx)) else digits Paul> If all values are small, mx is very small, log10(mx) Paul> is "large" but negative, digits - log10(mx) is very Paul> large, so no rounding occurs. This has very much been the intent of zapsmall AFAI have "forever" known (though the documentation unfortunately does not tell clearly so) : The "small" in "zapsmall(x)" is something *relative* to the other numbers in `x'. If you know in advance that 1e-24 is small (it isn't, compared to 1e-22 or even 1e-50), then use round() with an explicit digits argument. Hence, the bug is only in the not-so-clear documentation. Martin