Re: representations




"Lane Straatman" <invalid@xxxxxxxxxxx> wrote in message > "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> wrote in message

Do you know what sign, mantissa and exponent mean, in relation to floating point numbers?
There was a recent thread with Joe Wright and others that is probably as much as I know about it. The sign will take a bit. The mantissa is the a in the a**x. The exponent is the exponent, x.

Nearly right.
IEEE standard floating point number use something very similar to scientific notation.
2000 is 2 * 10^3 in this notation.
By convention there is only one decimal digit before the point, so
2300 is 2.3 * 10^3
Numbers below one have negative exponents
0.023 = 2.3 * 10^-2 (mnemonic, count the zeroes, including the leading one)

2.3 itself is 2.3 * 10^0.

Floating point numbers are basically just the same, but in binary. Since the leading most significant binary digit must always be one, most representations including IEEE save a bit by omitting it. There is one exception to this rule, zero, so zero is represented specially by all bits zero. Since zero is 10^-inf, it makes sense to store exponents in a sign magnitude encoding rather than twos complement, so that 0 is the lowest, 1 = -127 or whatever, and so on. The sign bit is self explanatory.
Finally there are a few special representations for infinity, not a number, and what are called denormalised numbers, but you can ignore those for now.

By looking at the bit patterns in your compiler, you should be able to work out how many bits are allocated to each section, and what the exponent encoding is. Start with one and minus one to get the sign bit.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


.



Relevant Pages

  • Re: 32 bit floating point
    ... PCs typically used IEEE 754 floating point, ... mantissa. ... positive, one if negative, 6 is the exponent, and 1.234 is the ... value it supports is positive zero (thought evidently you can have ...
    (comp.lang.apl)
  • Re: representations
    ... among the numerics people to move to decimal floating point. ... representations including IEEE save a bit by omitting it. ... exception to this rule, zero, so zero is represented specially by all bits ... <snip rest> ...
    (comp.lang.c)
  • Re: t1lib, %SYSTEM-F-HPARITH
    ... (Not all bit representations ... >are valid floating-point numbers.) ... Zero is represented by all-zeroes. ... especially if the exponent is not offset as Vax ones are. ...
    (comp.os.vms)
  • Re: memset all bits to zero will let float/double to zero?
    ... There are other floating point representations ... |>where all bits zero doesn't mean zero. ... Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org ...
    (comp.lang.c)
  • Re: Random number generators
    ... There are more floating point values between 0 and .5 than there are ... About half of the exponent range. ... are about the same number of exponents less than zero as there are ... so about half of the exponent range corresponds ...
    (comp.lang.fortran)

Loading