# [R] Odd underflow(?) error

Martin Maechler maechler at stat.math.ethz.ch
Sat Dec 4 12:45:24 CET 2004

```>>>>> "TL" == Thomas Lumley <tlumley at u.washington.edu>
>>>>>     on Fri, 3 Dec 2004 15:22:07 -0800 (PST) writes:

TL> On Fri, 3 Dec 2004, William Faulk wrote:
>> I'm still trying to install R on my Irix machine.  Now I have a new problem
>> that crops up during the checks.  I've found the root cause, and it's that R
>> is returning zero for certain things for reasons I don't understand.
>>
>> 2.225073859e-308, entered directly into R, responds "2.225074e-308".
>> 2.225073858e-308 responds "0".
>>
>> Their negative values respond similarly, so it would appear that somewhere in
>> there is the smallest absolute value that that installation of R will hold.

TL> Yes.  .Machine\$double.xmin tells you the smallest number representable to
TL> full precision, which is 2.225074e-308 (I think on all machines where R
TL> works)

>> On another machine where the checks passed, both responses are correct, not
>> just the first one.  The underflow there is significantly lower, with much
>> less accuracy, as opposed to what seems to be good accuracy on what looks
>> like the broken one.  The values there are:
>>
>> 2.4703282293e-324 gives 4.940656e-324
>> 2.4703282292e-324 gives 0

TL> Machines can differ in what they do with numbers smaller than
TL> .Machine\$double.xmin. They can report zero, or they can add leading zeros
TL> and so lose precision.  Suppose you had a 4-digit base 10 machine with 2
TL> digits of exponent.  The smallest number representable to full accuracy
TL> would be
TL> 1.000e-99
TL> but by allowing the leading digits to be zero you could represent
TL> 0.001e-99
TL> ie, 1e-102, to one digit accuracy (these are called "denormalized"
TL> numbers).

TL> My Mac laptop denormalizes, and agrees with your other computer, giving
TL> the smallest representable number as 4.940656e-324. It is
TL> .Machine\$double.xmin/2^52.   This number has very few bits left to
TL> represent values, so for example
>> (a/2^52)*1.3==(a/2^52)
TL> [1] TRUE
TL> where a is .Machine\$double.xmin

(very nice explanation, thanks Thomas!)

TL> Both your machines should be correct. I don't think we deliberately
TL> require denormalized numbers to work anywhere.

yes, indeed.
I can imagine that some of regression tests (aka "validation" !)
implicitly use some property -- but as Thomas said, that's not
deliberate (and a buglet in our tests).

William, could you move this topic from R-help to R-devel and