The information in this article applies to:
The information in this article is included in the documentation starting with Visual C++ 5.0. Look there for future revisions. SUMMARYThe following information discusses how real*4 (single precision) and real*8 (double precision) numbers are stored internally by Microsoft languages that use the IEEE floating-point format. MORE INFORMATION
There are three internal varieties of real numbers. Microsoft is consistent
with the IEEE numeric standards. Real*4 and real*8 are used in all of our
languages. Real*10 is used with MASM and in the 16-bit versions of the C
compiler. In 16-bit applications, Real* 10 is the internal floating-point
format used in the numerical processors and coprocessors for the Intel
80x86 processor family and also in the emulator math package which emulates
the Intel processors.
In real*4 and real*8 formats, there is an assumed leading 1 in the
mantissa that is not stored in memory, so the mantissas are actually
24 or 53 bits, even though only 23 or 52 bits are stored. The real*10
format actually stores this bit.
The exponents are biased by half of their possible value. This means you subtract this bias from the stored exponent to get the actual exponent. If the stored exponent is less than the bias, it is actually a negative exponent. The exponents are biased as follows:
These exponents are not powers of ten; they are powers of two, that
is, 8-bit stored exponents can be up to 127. 2**127 is roughly
equivalent to 10**38, which is the actual limit of real*4.
The mantissa is stored as a binary fraction of the form 1.XXX... . This fraction has a value greater than or equal to 1 and less than 2. Note that real numbers are always stored in normalized form, that is, the mantissa is left-shifted such that the high-order bit of the mantissa is always 1. Because this bit is always 1, it is assumed (not stored) in the real*4 and real*8 formats. The binary (not decimal) point is assumed to be just to the right of the leading 1. The format, then, for the various sizes is as follows:
S represents the sign bit, the X's are the exponent bits, and the M's
are the mantissa bits. Note that the leftmost bit is assumed in real*4
and real*8 formats, but present as "1" in BYTE 3 of the real*10
format.
To shift the binary point properly, you first un-bias the exponent and then move the binary point to the right or left the appropriate number of bits. The following are some examples in real*4 format:
Note the sign bit is zero, and the stored exponent is 128, or 100 0000 0 in binary, which is 127 plus 1. The stored mantissa is (1.) 000 0000 ... 0000 0000, which has an implied leading 1 and binary point, so the actual mantissa is one.
Same as +2 except that the sign bit is set. This is true for all IEEE format floating-point numbers.
Same mantissa, exponent increases by one (biased value is 129, or 100 0000 1 in binary.
Same exponent, mantissa is larger by half--it's (1.) 100 0000 ... 0000 0000, which, since this is a binary fraction, is 1 1/2 (the values of the fractional digits are 1/2, 1/4, 1/8, and so forth.).
Same exponent as other powers of two, mantissa is one less than two at 127, or 011 1111 1 in binary.
The biased exponent is 126, 011 1111 0 in binary, and the mantissa is (1.) 100 0000 ... 0000 0000, which is 1 1/2.
Exactly the same as two except that the bit that represents 1/4 is set in the mantissa.
1/10 is a repeating fraction in binary. The mantissa is just shy of 1.6, and the biased exponent says that 1.6 is to be divided by 16 (it is 011 1101 1 in binary, which is 123 in decimal). The true exponent is 123 - 127 = -4, which means that the factor by which to multiply is 2**-4 = 1/16. Note that the stored mantissa is rounded up in the last bit -- an attempt to represent the unrepresentable number as accurately as possible. (The reason that 1/10 and 1/100 are not exactly representable in binary similar to the reason that 1/3 is not exactly representable in decimal.)
Additional query words: kbinf 1.00 1.50 2.00 2.10 4.00 5.10 6.00 6.00a 6.00ax 7.00 8.00 8.00c 9.00 9.10 floating point 8087 80287 80387 80486 pentium \* swept by: v-aarod, 9/8/95
Keywords : kbFortranPS kbLangC kbLangFortran kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC600 MASMLngIss |
Last Reviewed: January 4, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |