Half-precision floating-point format
In computing, half precision is a binary floating-point computer number format that occupies 16 bits in computer memory. It is intended for storage of floating-point values in applications where higher precision is not essential, in particular image processing and neural networks.
Almost all modern uses follow the IEEE 754-2008 standard, where the 16-bit base-2 format is referred to as binary16, and the exponent uses 5 bits. This can express values in the range ±65,504, with the minimum value above 1 being 1 + 1/1024.
History
Several earlier 16-bit floating point formats have existed including that of Hitachi's HD61810 DSP of 1982, the top 16 bits of a 32-bit float called a bfloat16, and Thomas J. Scott's WIF of 1991 and the 3dfx Voodoo Graphics processor of 1995.ILM was searching for an image format that could handle a wide dynamic range, but without the hard drive and memory cost of single or double precision floating point. The hardware-accelerated programmable shading group led by John Airey at SGI used the s10e5 data type in 1997 as part of the "bali" design effort. This is described in a SIGGRAPH 2000 paper and further documented in US patent 7518615. It was popularized by its use in the open-source OpenEXR image format.
Nvidia and Microsoft defined the half datatype in the Cg language, released in early 2002, and implemented it in silicon in the GeForce FX, released in late 2002. However, hardware support for accelerated 16-bit floating point was later dropped by Nvidia before being reintroduced in the Tegra X1 mobile GPU in 2015.
The F16C extension in 2012 allows x86 processors to convert half-precision floats to and from single-precision floats with a machine instruction.
IEEE 754 half-precision binary floating-point format: binary16
The IEEE 754 standard specifies a binary16 as having the following format:- Sign bit: 1 bit
- Exponent width: 5 bits
- Significand precision: 11 bits
The format is assumed to have an implicit lead bit with value 1 unless the exponent field is stored with all zeros. Thus, only 10 bits of the significand appear in the memory format but the total precision is 11 bits. In IEEE 754 parlance, there are 10 bits of significand, but there are 11 bits of significand precision.
Exponent encoding
The half-precision binary floating-point exponent is encoded using an offset-binary representation, with the zero offset being 15; also known as exponent bias in the IEEE 754 standard.- Emin = 000012 − 011112 = −14
- Emax = 111102 − 011112 = 15
- Exponent bias = 011112 = 15
The stored exponents 000002 and 111112 are interpreted specially.
The minimum strictly positive value is
2−24 ≈ 5.96 × 10−8.
The minimum positive normal value is 2−14 ≈ 6.10 × 10−5.
The maximum representable value is × 215 = 65504.
Half precision examples
These examples are given in bit representationof the floating-point value. This includes the sign bit, exponent, and significand.
| Binary | Hex | Value | Notes |
| smallest positive subnormal number | |||
| largest subnormal number | |||
| smallest positive normal number | |||
| nearest value to 1/3 | |||
| largest number less than one | |||
| one | |||
| smallest number larger than one | |||
| largest odd number | |||
| largest normal number | |||
| closest value to π | |||
| infinity | |||
| - | |||
| - | |||
| negative infinity |
By default, 1/3 rounds down like for double precision, because of the odd number of bits in the significand. The bits beyond the rounding point are... which is less than 1/2 of a unit in the last place.
ARM alternative half-precision
ARM processors support an "alternative half-precision" format, which does away with the special case for an exponent value of 31. It is almost identical to the IEEE format, but there is no encoding for infinity or NaNs; instead, an exponent of 31 encodes normalized numbers in the range 65536 to 131008.Uses of half precision
Half precision is used in several computer graphics environments to store pixels, including MATLAB, OpenEXR, JPEG XR, GIMP, OpenGL, Vulkan, Cg, Direct3D, and D3DX. The advantage over 8-bit or 16-bit integers is that the increased dynamic range allows for more detail to be preserved in highlights and shadows for images, and avoids gamma correction. The advantage over 32-bit single-precision floating point is that it requires half the storage and bandwidth.Half precision can be useful for mesh quantization. Mesh data is usually stored using 32-bit single-precision floats for the vertices, however in some situations it is acceptable to reduce the precision to only 16-bit half-precision, requiring only half the storage at the expense of some precision. Mesh quantization can also be done with 8-bit or 16-bit fixed precision depending on the requirements.
Hardware and software for machine learning or neural networks tend to use half precision: such applications usually do a large amount of calculation, but don't require a high level of precision. Due to hardware typically not supporting 16-bit half-precision floats, neural networks often use the bfloat16 format, which is the single precision float format truncated to 16 bits.
If the hardware has instructions to compute half-precision math, it is often faster than single or double precision. If the system has SIMD instructions that can handle multiple floating-point numbers within one instruction, half precision can be twice as fast by operating on twice as many numbers simultaneously.
Support by programming languages
provides support for half precisions with itsf16 type..NET 5 introduced half precision floating point numbers with the
System.Half standard library type., no.NET language has literals or a keyword for the type.Swift introduced half-precision floating point numbers in Swift 5.3 with the type.
OpenCL also supports half-precision floating point numbers with the half datatype on IEEE 754-2008 half-precision storage format.
, Rust is currently working on adding a new
f16 type for IEEE half-precision 16-bit floats.Julia provides support for half-precision floating point numbers with the
Float16 type.C++ introduced half-precision since C++23 with the
std::float16_t type. GCC already implements support for it.Hardware support
Several versions of the ARM architecture have support for half precision.Support for conversions with half-precision floats in the x86 instruction set is specified in the F16C instruction set extension, first introduced in 2009 by AMD and fairly broadly adopted by AMD and Intel CPUs by 2012. This was further extended up the AVX-512_FP16 instruction set extension implemented in the Intel Sapphire Rapids processor.
On RISC-V, the
Zfh and Zfhmin extensions provide hardware support for 16-bit half precision floats. The Zfhmin extension is a minimal alternative to Zfh.On Power ISA, VSX and the not-yet-approved SVP64 extension provide hardware support for 16-bit half-precision floats as of PowerISA v3.1B and later.
Support for half precision on IBM Z is part of the Neural-network-processing-assist facility that IBM introduced with Telum. IBM refers to half precision floating point data as NNP-Data-Type 1.