Floating Type Formats <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
The Compiler supports two IEEE floating point formats: IEEE32 and IEEE64. There may also be a DSP format supported by the processor. The figure below shows these three formats.
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
Floats are implemented as IEEE32, and doubles as IEEE64. This may vary for a specific Back End, or possibly, both formats may not be supported. Please check the Back End chapter for details, default settings and supported formats.
Floating Point Representation of 500.0 for IEEE
First convert 500.0 from the decimal representation to a representation with base 2:
value = (-1)^s * m*2^e
where sign is 0 or 1,
2 > m >= 1 for IEEE
and exp is a integral number.
sign (500.0) = 1
mant (500.0,IEEE) = 1.953125
NOTE The number 0 (zero) can not be represented this way. So for 0 IEEE defines a special bit pattern consisting of 0 bits only. |
Next convert the mantissa into its binary representation.
mant (500.0,IEEE) = 1.953125
= 1*2^(0) + 1*2^(-1) + 1*2^(-2) + 1*2^(-3) + 1*2^(-4)
+ 0*2^(-5) + 1*2^(-6) + 0*....
Because this number is computed to be larger or equal to 1 and smaller than 2, there is always a <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1 in front of the decimal point. For the remaining steps, this constant 1 is left out to save space.
mant (500.0, IEEE, cutted) = .111101000... .
The exponent must also be converted to binary format:
exp (500.0,IEEE) = 8 == 08 (hex) == 1000 (bin)
For the IEEE formats the sign is encoded as separate bit (sign magnitude representation)
Representation of 500.0 in IEEE32 Format
The exponent in IEEE32 has a fixed offset of 127 to always have positive values:
exp (500.0,IEEE32) = 8+127 == 87 (hex) == 10000111 (bin)
The fields must be put together according to the graphic:
500.0 (dec)
= 0 (sign) 10000111 (exponent)
11110100000000000000000 (mantissa) (IEEE32 as bin)
= 0100 0011 1111 1010 0000 0000 0000 0000 (IEEE32 as bin)
-500.0 (dec)
= 1 (sign) 10000111 (exponent)
11111010000000000000000 (mantissa) (IEEE32 as bin)
= 1100 0011 1111 1010 0000 0000 0000 0000 (IEEE32 as bin)
Representation of 500.0 in IEEE64 Format
The exponent in IEEE64 has a fixed offset of 1023 to always have positive values:
exp (500.0,IEEE64) = 8+1023 == 407 (hex) == 10000000111
The IEEE64 format is similar to IEEE32 except that more bits are used to represent the exponent and the mantissa.
500.0 (dec)
= 0 (sign) 10000000111 (exponent)
1111010000000000000000000000000000000000000000000000
(mantissa)
(IEEE64 as bin)
= 0100 0000 0111 1111 0100 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 (IEEE64 as bin)
= 40 7f 40 00 00 00 00 00 (IEEE64 as hex)
-500.0 (dec)
= 1 (sign) 10000000111 (exponent)
1111010000000000000000000000000000000000000000000000
(mantissa)
(IEEE64 as bin)
= 1100 0000 0111 1111 0100 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 (IEEE64 as bin)
= c0 7f 40 00 00 00 00 00 (IEEE64 as hex)
Representation of 500.0 in DSP Format
Convert 500.0 from the decimal representation to a representation with base 2. In contradiction to IEEE, DSP normalizes the mantissa between 0 and 1 and not between 1 and 2. This makes it possible to also represent 0, which must have a special pattern in IEEE. Also, the exponent is different from IEEE.
value = (-1)^s * m*2^e
where sign is 1 or -1,
1 > m >= 0
and exp is a integral number.
sign (500.0) = 1
mant (500.0,DSP) = 0.9765625
Next convert the mantissa into its binary representation.
mant (500.0, DSP) = 0.9765625 (dec)
= 0*2^(0) + 1*2^(-1) + 1*2^(-2) + 1*2^(-3) + 1*2^(-4) +
1*2^(-5)
+ 0*2^(-6) + 1*2^(-7) + 0*....
Because this number is computed to be always larger or equal to 0 and smaller than 1, there is always a 0 in front of the decimal point . For the remaining steps this constant is left out to save space. There is always a 1 after the decimal point, except for 0 and intermediate results. This bit is encoded, so the DSP looses one additional bit of precision compared with IEEE.
mant (500.0, DSP, cutted) = .1111101000... .
The exponent must also be converted to binary format:
exp (500.0,DSP) = 9 == 09 (hex) == 1001 (bin)
Negative exponents are encoded by the 2's representation of the positive value.
The sign is encoded into the mantissa by taking the 2's complement for negative numbers and adding a 1 bit in the front. For DSP and positive numbers a 0 bit is added at the front.
mant(500.0, DSP) = 0111110100000000 (bin)
The twos complement is taken for negative numbers:
mant(-500.0, DSP) = 1000001100000000 (bin)
Finally the mantissa and the exponent must be joined according to the graphic above:
500.0 (dec)
= 7D 00 (mantissa) 00 09 (exponent) (DSP as hex)
= 7D 00 00 09 (DSP as hex)
= 0111 1101 0000 0000 0000 0000 0000 1001 (DSP as bin)
-500.0 (dec)
= 83 00 (mantissa) 00 09 (exponent) (DSP as hex)
= 83 00 00 09 (DSP as hex)
= 1000 0011 0000 0000 0000 0000 0000 1001 (DSP as bin)
文章评论(0条评论)
登录后参与讨论