Single-precision floating-point format (sometimes called FP32 or float32) is a computer number format, usually occupying 32 bits in computer memory; it represents a wide dynamic range of numeric values by using a floating radix point.
All integers with seven or fewer decimal digits, and any 2n for a whole number −149 ≤ n ≤ 127, can be converted exactly into an IEEE 754 single-precision floating-point value.
IEEE 754 specifies additional floating-point types, such as 64-bit base-2 double precision and, more recently, base-10 representations.
One of the first programming languages to provide single- and double-precision floating-point data types was Fortran.
Before the widespread adoption of IEEE 754-1985, the representation and properties of floating-point data types depended on the computer manufacturer and computer model, and upon decisions made by programming-language designers.
E.g., GW-BASIC's single-precision data type was the 32-bit MBF floating-point format.
Single precision is termed REAL in Fortran;[1] SINGLE-FLOAT in Common Lisp;[2] float in C, C++, C# and Java;[3] Float in Haskell[4] and Swift;[5] and Single in Object Pascal (Delphi), Visual Basic, and MATLAB.
However, float in Python, Ruby, PHP, and OCaml and single in versions of Octave before 3.2 refer to double-precision numbers.
In most implementations of PostScript, and some embedded systems, the only supported precision is single.
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.
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.
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 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.
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.
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
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
However, due to the default rounding behaviour of IEEE 754 format, what you get is
From which we deduce: 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.
From which we deduce: 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 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 can now decode the significand by adding the values represented by these bits.
These examples are given in bit representation, in hexadecimal and binary, of the floating-point value.
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.
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.