For an N-bit signed integer stored in two's complement, the range is -(2^(N-1)) to 2^(N-1) - 1.

But floating point numbers (in the types float and double) are not stored the same way as integers; they are stored in the IEEE 754 format. See that page for details on the layout of float and double in memory. [ July 13, 2007: Message edited by: Jesper Young ]

Float runs from (1 - 2^-24) * 2 ^128 to 2^-126 with a subnormal range down to 2^149.

The first bit is the sign bit. The next 8 bits are the exponent, in binary, but biased by 127, so X100_0000_0 means an exponent of +1, but in binary. The remaining 23 bits represent the fractional part of the mantissa, with an imaginary 1 before the radix point. In the case of subnormal numbers, the exponent is X000_0000_0 which is equivalent to -126 and the mantissa is the remaining 23 digits as a fraction following an imaginary 0 before the radix point. As the mantissa gets smaller, the precision does too, until 0000_0000_0000_0000_0000_0000_0000_0001 is half of 0000_0000_0000_0000_0000_0000_0000_0010 and the next smaller value (X000_0000_0000_0000_0000_0000_0000_0000) means plus zero or minus zero. If the exponent is X111_1111_1 and all the other figures are zero, then you have infinity (or minus infinity). If the exponent is X111_1111_1 and there is a 1 anywhere else, you have "NaN".

Bet you wish you had never asked, now.

If you really want to know, you need to find a Computer Technologies course, which we have here as a module in the Computing BSc for freshers. There is an article in Wikipedia, but I don't think it makes it much clearer. There are bits in the computer hardware books (eg Alan Clements, Principles of Computer Hardware, 3/e, Oxford: OUP [2000], pages 184ff).

vatsalya rao
Ranch Hand

Joined: Feb 14, 2007
Posts: 63

posted

0

Thanks lot for both of you for explaining

in such a detailed manner.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41552

31

posted

0

You're welcome, but I don't think we explained a lot. I think there are two lectures in our Principles of Computing course about floating-point arithmetic and numbers, so there is a lot to the subject.