Single-precision floating-point format (sometimes called FP32 or float32) is a
computer number format, usually occupying
32 bits in
computer memory
In computing, memory is a device or system that is used to store information for immediate use in a computer or related computer hardware and digital electronic devices. The term ''memory'' is often synonymous with the term '' primary storage ...
; it represents a wide
dynamic range of numeric values by using a
floating radix point.
A floating-point variable can represent a wider range of numbers than a
fixed-point variable of the same bit width at the cost of precision. A
signed 32-bit
integer
An integer is the number zero (), a positive natural number (, , , etc.) or a negative integer with a minus sign ( −1, −2, −3, etc.). The negative numbers are the additive inverses of the corresponding positive numbers. In the language ...
variable has a maximum value of 2
31 − 1 = 2,147,483,647, whereas an
IEEE 754 32-bit base-2 floating-point variable has a maximum value of (2 − 2
−23) × 2
127 ≈ 3.4028235 × 10
38. All integers with 7 or fewer decimal digits, and any 2
''n'' for a whole number −149 ≤ ''n'' ≤ 127, can be converted exactly into an IEEE 754 single-precision floating-point value.
In the
IEEE 754-2008 standard, the 32-bit base-2 format is officially referred to as binary32; it was called single in
IEEE 754-1985. 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 language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming l ...
s 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
GW-BASIC is a dialect of the BASIC programming language developed by Microsoft from IBM BASICA. Functionally identical to BASICA, its BASIC interpreter is a fully self-contained executable and does not need the Cassette BASIC ROM found in the ori ...
's single-precision data type was the
32-bit MBF floating-point format.
Single precision is termed ''REAL'' in
Fortran, ''SINGLE-FLOAT'' in
Common Lisp, ''float'' in
C,
C++,
C#,
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
, ''Float'' in
Haskell and
Swift,
and ''Single'' in
Object Pascal (
Delphi
Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracl ...
),
Visual Basic, and
MATLAB
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
. However, ''float'' in
Python,
Ruby
A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum (aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called sapp ...
,
PHP
PHP is a General-purpose programming language, general-purpose scripting language geared toward web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementati ...
, and
OCaml and ''single'' in versions of
Octave before 3.2 refer to
double-precision numbers. In most implementations of
PostScript
PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, ...
, and some
embedded systems, the only supported precision is single.
IEEE 754 standard: binary32
The IEEE 754 standard specifies a ''binary32'' as having:
*
Sign bit
In computer science, the sign bit is a bit in a signed number representation that indicates the sign of a number. Although only signed numeric data types have a sign bit, it is invariably located in the most significant bit position, so the te ...
: 1 bit
*
Exponent
Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
width: 8 bits
*
Significand
The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
precision: 24 bits (23 explicitly stored)
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 sign bit determines the sign of the number, which is the sign of the significand as well. The exponent is an 8-bit unsigned integer from 0 to 255, in
biased form: an exponent value of 127 represents the actual zero. Exponents range from −126 to +127 because exponents of −127 (all 0s) and +128 (all 1s) are reserved for special numbers.
The true significand 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, unless the exponent is stored with all zeros. Thus only 23 fraction bits of the
significand
The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
appear in the memory format, but the total precision is 24 bits (equivalent to log
10(2
24) ≈ 7.225 decimal digits). 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:
*
,
*
,
*
,
*
,
*