handling T.min the right way

Daniel Keep daniel.keep.lists at gmail.com
Tue Mar 20 17:06:55 PDT 2007



0ffh wrote:
> Frits van Bommel wrote:
>> Does "normalized" imply non-negative?
> 
> No, I think it just means the mantissa msb is 1.
> 
> Happy hacking,
> 
>     0ffh

If I remember correctly, there are two kinds of non-infinite, non-nan,
non-zero IEEE floating point numbers: normalised and denormalised numbers.

Normal numbers are ones where, like 0ffh said, the number starts with an
implicit '1'.  Basically, with IEEE, if you wanted to store the binary
number 0b1.0101001, you would *actually* store the '0101001' part: every
binary number must has a leading '1' at *some* point, otherwise it'd be
zero :)

Now, the other kind of number, a denormal, comes about when your number
is so close to zero that IEEE runs out of full-precision numbers.  So
what happens here is that IEEE basically starts representing the number
using less and less bits, trying to prevent underflow (or overflow if
you're using negative numbers) to zero.[1]

This is useful where you're doing a calculation with numbers very close
to zero.  The result might be a normalised number, but the intermediates
are denormalised.  With support for denormal numbers, you get
(approximately) the correct, non-zero result.  Without them, you get zero.

IEEE is pretty interesting, in how much thought and care went into how
we represent numbers.  You can read more about Denormal numbers on
Wikipedia[2].  There's a link to Kahan's site, but the server seems to
be down atm.

	-- Daniel

[1] Incidentally, some people working on the IEEE spec felt that the
whole subnormal thing was a waste of time, that they couldn't be
implemented efficiently and that these numbers should just automatically
round to zero.  Thankfully, Kahan and Intel convinced them otherwise :)

[2] http://en.wikipedia.org/wiki/Denormal

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list