[Rd] zapsmall with all values small (PR#4554)

maechler at stat.math.ethz.ch maechler at stat.math.ethz.ch
Mon Oct 13 09:22:00 MEST 2003


>>>>> "Paul" == p murrell <p.murrell at 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



More information about the R-devel mailing list