The IEEE 754 standard specifies a binary32 as having:
This gives from 6 to 9 significant decimal digits precision. If a decimal string with at most 6 significant digits is converted to the IEEE 754 single-precision format, giving a normal number, and then converted back to a decimal string with the same number of digits, the final result should match the original string. If an IEEE 754 single-precision number is converted to a decimal string with at least 9 significant digits, and then converted back to single-precision representation, the final result must match the original number.6
The sign bit determines the sign of the number, which is the sign of the significand as well. "1" stands for negative. The exponent field is an 8-bit unsigned integer from 0 to 255, in biased form: a value of 127 represents the actual exponent zero. Exponents range from −126 to +127 (thus 1 to 254 in the exponent field), because the biased exponent values 0 (all 0s) and 255 (all 1s) are reserved for special numbers (subnormal numbers, signed zeros, infinities, and NaNs).
The true significand of normal numbers includes 23 fraction bits to the right of the binary point and an implicit leading bit (to the left of the binary point) with value 1. Subnormal numbers and zeros (which are the floating-point numbers smaller in magnitude than the least positive normal number) are represented with the biased exponent value 0, giving the implicit leading bit the value 0. Thus only 23 fraction bits of the significand appear in the memory format, but the total precision is 24 bits (equivalent to log10(224) ≈ 7.225 decimal digits) for normal values; subnormals have gracefully degrading precision down to 1 bit for the smallest non-zero value.
The bits are laid out as follows:
The real value assumed by a given 32-bit binary32 data with a given sign, biased exponent e (the 8-bit unsigned integer), and a 23-bit fraction is
which yields
In this example:
thus:
Note:
The single-precision binary floating-point exponent is encoded using an offset-binary representation, with the zero offset being 127; also known as exponent bias in the IEEE 754 standard.
Thus, in order to get the true exponent as defined by the offset-binary representation, the offset of 127 has to be subtracted from the stored exponent.
The stored exponents 00H and FFH are interpreted specially.
The minimum positive normal value is 2 − 126 ≈ 1.18 × 10 − 38 {\displaystyle 2^{-126}\approx 1.18\times 10^{-38}} and the minimum positive (subnormal) value is 2 − 149 ≈ 1.4 × 10 − 45 {\displaystyle 2^{-149}\approx 1.4\times 10^{-45}} .
In general, refer to the IEEE 754 standard itself for the strict conversion (including the rounding behaviour) of a real number into its equivalent binary32 format.
Here we can show how to convert a base-10 real number into an IEEE 754 binary32 format using the following outline:
Conversion of the fractional part: Consider 0.375, the fractional part of 12.375. To convert it into a binary fraction, multiply the fraction by 2, take the integer part and repeat with the new fraction by 2 until a fraction of zero is found or until the precision limit is reached which is 23 fraction digits for IEEE 754 binary32 format.
We see that ( 0.375 ) 10 {\displaystyle (0.375)_{10}} can be exactly represented in binary as ( 0.011 ) 2 {\displaystyle (0.011)_{2}} . Not all decimal fractions can be represented in a finite digit binary fraction. For example, decimal 0.1 cannot be represented in binary exactly, only approximated. Therefore:
Since IEEE 754 binary32 format requires real values to be represented in ( 1. x 1 x 2 . . . x 23 ) 2 × 2 e {\displaystyle (1.x_{1}x_{2}...x_{23})_{2}\times 2^{e}} format (see Normalized number, Denormalized number), 1100.011 is shifted to the right by 3 digits to become ( 1.100011 ) 2 × 2 3 {\displaystyle (1.100011)_{2}\times 2^{3}}
Finally we can see that: ( 12.375 ) 10 = ( 1.100011 ) 2 × 2 3 {\displaystyle (12.375)_{10}=(1.100011)_{2}\times 2^{3}}
From which we deduce:
From these we can form the resulting 32-bit IEEE 754 binary32 format representation of 12.375:
Note: consider converting 68.123 into IEEE 754 binary32 format: Using the above procedure you expect to get ( 42883EF9 ) 16 {\displaystyle ({\text{42883EF9}})_{16}} with the last 4 bits being 1001. However, due to the default rounding behaviour of IEEE 754 format, what you get is ( 42883EFA ) 16 {\displaystyle ({\text{42883EFA}})_{16}} , whose last 4 bits are 1010.
Example 1: Consider decimal 1. We can see that: ( 1 ) 10 = ( 1.0 ) 2 × 2 0 {\displaystyle (1)_{10}=(1.0)_{2}\times 2^{0}}
From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 1:
Example 2: Consider a value 0.25. We can see that: ( 0.25 ) 10 = ( 1.0 ) 2 × 2 − 2 {\displaystyle (0.25)_{10}=(1.0)_{2}\times 2^{-2}}
From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 0.25:
Example 3: Consider a value of 0.375. We saw that 0.375 = ( 0.011 ) 2 = ( 1.1 ) 2 × 2 − 2 {\displaystyle 0.375={(0.011)_{2}}={(1.1)_{2}}\times 2^{-2}}
Hence after determining a representation of 0.375 as ( 1.1 ) 2 × 2 − 2 {\displaystyle {(1.1)_{2}}\times 2^{-2}} we can proceed as above:
From these we can form the resulting 32-bit IEEE 754 binary32 format representation of real number 0.375:
If the binary32 value, 41C80000 in this example, is in hexadecimal we first convert it to binary:
then we break it down into three parts: sign bit, exponent, and significand.
We then add the implicit 24th bit to the significand:
and decode the exponent value by subtracting 127:
Each of the 24 bits of the significand (including the implicit 24th bit), bit 23 to bit 0, represents a value, starting at 1 and halves for each bit, as follows:
The significand in this example has three bits set: bit 23, bit 22, and bit 19. We can now decode the significand by adding the values represented by these bits.
Then we need to multiply with the base, 2, to the power of the exponent, to get the final result:
Thus
This is equivalent to:
where s is the sign bit, x is the exponent, and m is the significand.
These examples are given in bit representation, in hexadecimal and binary, of the floating-point value. This includes the sign, (biased) exponent, and significand.
By default, 1/3 rounds up, instead of down like double precision, because of the even number of bits in the significand. The bits of 1/3 beyond the rounding point are 1010... which is more than 1/2 of a unit in the last place.
Encodings of qNaN and sNaN are not specified in IEEE 754 and implemented differently on different processors. The x86 family and the ARM family processors use the most significant bit of the significand field to indicate a quiet NaN. The PA-RISC processors use the bit to indicate a signaling NaN.
The design of floating-point format allows various optimisations, resulting from the easy generation of a base-2 logarithm approximation from an integer view of the raw bit pattern. Integer arithmetic and bit-shifting can yield an approximation to reciprocal square root (fast inverse square root), commonly required in computer graphics.
"REAL Statement". scc.ustc.edu.cn. Archived from the original on 2021-02-24. Retrieved 2013-02-28. https://web.archive.org/web/20210224045812/http://scc.ustc.edu.cn/zlsc/sugon/intel/compiler_f/main_for/lref_for/source_files/rfreals.htm ↩
"CLHS: Type SHORT-FLOAT, SINGLE-FLOAT, DOUBLE-FLOAT..." www.lispworks.com. https://www.lispworks.com/documentation/HyperSpec/Body/t_short_.htm ↩
"Primitive Data Types". Java Documentation. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html ↩
"6 Predefined Types and Classes". haskell.org. 20 July 2010. https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1350006.4 ↩
"Float". Apple Developer Documentation. https://developer.apple.com/documentation/swift/float ↩
William Kahan (1 October 1997). "Lecture Notes on the Status of IEEE Standard 754 for Binary Floating-Point Arithmetic" (PDF). p. 4. Archived from the original (PDF) on 8 February 2012. https://web.archive.org/web/20120208075518/http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF ↩