"Sheldon Simms" <sh**********@yahoo.com> wrote in message
news:pa****************************@yahoo.com...
I would like to portably extract the components of a floating point value:
sign, exponent, and significand. Based on the C floating point model
described in 5.2.4.2.2, I came up with the following code. There are
a couple of things to note about this code.
1) I convert the significand to an integer value in which the least
significant bit(s) of the integer correspond/s to the least significant
digit of the significand. This means that only as many low-order bits as
needed to encode DBL_MANT_DIG digits of the floating point radix are
significant in the integer value.
2) I assume that an unsigned long long int is large enough to represent
the significand. If this isn't true, the integer value used to represent
the significand will silently overflow.
(snip)
There are machines with 128 bit floating point representations, with
something like 112 bits for mantissa.
You might consider whether your code works correctly for FLT_RADIX of 10 or
16. There is work on a standard for FLT_RADIX of 10, though with a slightly
more compact storage format than BCD. IBM has been making machines with
FLT_RADIX of 16 for almost 40 years now.
-- glen