IEEE-754 Floating-Point Inspector

Decimal input accepts 0.1, -2.5e-3, Infinity, NaN or -0. Hex input needs every digit of the pattern: 4 for half, 8 for single, 16 for double.

Bit pattern

Exact stored value

Sign
Exponent
Fraction
Significand
Shortest decimal
Rounding error
Spacing (ULP)

Sign Exponent Fraction

Illustration: the bits of the value, most significant first: the sign bit, then the exponent field, then the fraction field.

Inspection needs JavaScript. If it does not load, the explanation, formulas and examples below remain available.

Decode half, single and double precision values into sign, exponent and fraction bits, with the exact stored value and its rounding error.

How to use

Choose the format: half (16-bit), single (32-bit, C float) or double (64-bit, C double and JavaScript numbers).

Choose whether you are entering a decimal number or the stored bit pattern in hex, then type it. The tool starts with 0.1.

Read the pattern, the class and the fields. The stored value shows exactly what the float equals, and the rounding error shows how far that is from what you typed.

Select any bit in the grid to flip it and see the effect on the value. The input switches to the hex pattern.

Copy the pattern or all results. Reset restores the starting example, format and input type.

Science

A binary floating-point number stores a sign, an exponent and a fraction. For normal numbers the value is (−1)^sign × 2^exponent × 1.fraction. The leading 1 is implied and not stored, which gains one bit of precision. Half, single and double precision have 11, 24 and 53 significant bits.

The exponent is stored with a bias (15, 127 or 1023), so the field is an unsigned number. All-zero and all-one exponent fields are reserved. All zeros with a zero fraction is ±0; with a non-zero fraction it is a subnormal number, which fills the gap near zero with reduced precision. All ones is ±infinity, or NaN when the fraction is non-zero.

Most decimal fractions, including 0.1, have no finite binary expansion, so they are rounded to the nearest representable value; exact ties go to the value with an even last bit. The stored value of 0.1 in single precision is 0.100000001490116119384765625. Printing the shortest decimal that rounds back to the same float gives 0.1 again, which is why the error is easy to miss.

The spacing between neighbouring floats (one ULP) doubles at each power of two. In single precision, whole numbers above 16,777,216 (2^24) can no longer all be stored. In double precision the same limit is 2^53, the safe-integer limit of JavaScript.

Values beyond the largest finite float round to infinity: for half precision that happens from 65,520 upward, although the largest finite value is 65,504. Values no larger than half of the smallest subnormal round to zero (an exact half is a tie and goes to the even value, zero).

Limitations: this tool uses only the default rounding (round to nearest, ties to even). It does not cover decimal floating-point formats, 128-bit, bfloat16 or 80-bit extended formats, and it does not do arithmetic between floats. NaN input is stored as the standard quiet NaN; other NaN payloads can be entered as hex.

Bit patterns are shown with the most significant bit first, as a debugger shows a value held in a register. Memory dumps of little-endian processors list the bytes in the reverse order.

Formulas

Normal: x = (−1)^S × 2^(E − bias) × (1 + T / 2^(p−1))

Subnormal: x = (−1)^S × 2^(1 − bias) × (T / 2^(p−1))

Parameters: half: p = 11, bias = 15; single: p = 24, bias = 127; double: p = 53, bias = 1023

Spacing: ULP = 2^(e − p + 1)

Rounding error: stored value − entered value

Overflow threshold: 2^emax × (2 − 2^−p) (rounds to infinity)

Examples

0.1 as single precision (binary32): 0x3DCCCCCD; stored 0.100000001490116119384765625; error +1.490116119384765625e-9. Sign 0, exponent 123 − 127 = −4, fraction 0x4CCCCD. The last bit rounded up.

0.1 as double precision (binary64): 0x3FB999999999999A; stored 0.1000000000000000055511151231257827021181583404541015625. The same repeating pattern 1001…, with 29 more bits.

16777217 as single precision: 0x4B800000; stored 16777216; error -1. Above 2^24 the spacing is 2. The tie goes to the even significand.

65520 as half precision: infinity (0x7C00). A common surprise. 65520 is halfway between 65504 and 65536, ties go to even, and 65536 is beyond the format, so the result is infinity.

pattern 0x00000001 as single precision: subnormal; stored 1.40129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125e-45; shortest 1e-45. The smallest positive single-precision value, 2^-149.

References

IEEE 754-2019: Standard for Floating-Point Arithmetic

Goldberg: What Every Computer Scientist Should Know About Floating-Point Arithmetic

ECMAScript: Number values and toPrecision