Skip to content
KmapGen

IEEE 754 Double Precision Converter (64-Bit)

Convert decimals to IEEE 754 double precision (binary64) and back: all 64 bits, the exact value a double really holds, and the rounding error down to the last digit.

Try:

Decimal input accepts -1.5e-3, fractions like 1/3, C hex floats like 0x1.8p3, pi, inf and nan. Conversion is exact: no intermediate rounding through a double.

Bits (click to flip)

sign · exponent · fraction · bit 63 on the left

Value stored (exact)0.1000000000000000055511151231257827021181583404541015625
Shortest round-trip decimal0.1
Rounding error (stored − input)0.0000000000000000055511151231257827021181583404541015625
≈ 5.55112e-18, relative 5.551e-17
Hexadecimal0x3FB999999999999A
Binary0 01111111011 1001100110011001100110011001100110011001100110011010
Sign0 (positive)
Exponentfield 01111111011 = 1019; bias 1023; actual exponent -4
Fraction (mantissa)1001100110011001100110011001100110011001100110011010 = 2702159776422298 / 252 (hidden leading 1 added)
Formula(+1) × 1.600000000000000088817841970012523233890533447265625 × 21019 − 1023 = (+1) × 1.600000000000000088817841970012523233890533447265625 × 2-4
CategoryNormal number
Gap to next value (ULP)2-56 ≈ 1.38778e-17
Next value up / down0.10000000000000002 (0x3FB999999999999B)
0.09999999999999999 (0x3FB9999999999999)

Decimal → IEEE 754, step by step

  1. Sign. The number is positive, so the sign bit is 0.
  2. Convert |x| to binary. 0.1 = 0.000112 (the overlined block repeats forever).
  3. Normalize. Move the binary point so one 1 is left of it: |x| = 1.… × 2-4.
  4. Exponent. Add the bias: -4 + 1023 = 1019 = 011111110112.
  5. Fraction. Keep the 52 bits after the leading 1. The bits beyond them are not all zero, so the value is rounded to the nearest representable number (ties go to the even one). Fraction = 1001100110011001100110011001100110011001100110011010.
  6. Assemble sign | exponent | fraction: 0 01111111011 1001100110011001100110011001100110011001100110011010 = 0x3FB999999999999A.

Double-precision layout

  • Sign: bit 63.
  • Exponent: bits 62–52 (11 bits), bias 1023; normal exponents from −1022 to +1023.
  • Fraction: bits 51–0 (52 bits) plus the hidden 1: 53 significant bits.
  • Value of a normal double: (−1)s × 1.f × 2e − 1023.

What a double really stores

You typeHexExact stored value
0.10x3FB999999999999A0.1000000000000000055511151231257827021181583404541015625
0.20x3FC999999999999A0.200000000000000011102230246251565404236316680908203125
0.30x3FD33333333333330.299999999999999988897769753748434595763683319091796875
0.300000000000000040x3FD33333333333340.3000000000000000444089209850062616169452667236328125
10x3FF00000000000001
90071992547409930x43400000000000009007199254740992
1e3080x7FE1CCF385EBC8A0100000000000000001097906362944045541740492309677311846336810…430223118336
5e-3240x00000000000000010.0000000000000000000000000000000000000000000000000000000000…533447265625

Every finite double has a finite decimal expansion (a binary fraction with k bits after the point has exactly k decimal digits after the point), so the converter can print it in full. The shortest string that converts back to the same bits is what languages print by default: that is why the stored value of 0.1 still prints as “0.1”.

Worked example: 0.1 to double

  1. 0.1 = 0.0001100110011…2, with 0011 repeating forever.
  2. Normalize: 1.100110011…2 × 2−4. Exponent field: −4 + 1023 = 1019 = 01111111011.
  3. The fraction is 1001 repeated, cut at 52 bits: the bits that follow (1001…) are more than half an ULP, so the last bit rounds up, giving …1010 at the end.
  4. Result: 0x3FB999999999999A = 0.1000000000000000055511151231257827021181583404541015625.

Frequently asked questions

What is IEEE 754 double precision?

Double precision (binary64) is the 64-bit IEEE 754 format: 1 sign bit, 11 exponent bits with a bias of 1023, and 52 fraction bits. With the hidden bit it carries 53 significant bits, about 15–17 decimal digits. It is the type of double in C, C++, Java and C#, float in Python, and every Number in JavaScript.

Why does 0.1 + 0.2 not equal 0.3?

Neither 0.1 nor 0.2 is exact in binary. Their stored values are slightly above the decimal ones, and the rounded sum is 0x3FD3333333333334, which prints as 0.30000000000000004. The double closest to 0.3 is 0x3FD3333333333333, one ULP lower. The two differ by 2−54 ≈ 5.55 × 10−17.

What is the largest integer a double can store exactly?

Every integer up to 253 = 9,007,199,254,740,992 is exact. Beyond that the spacing between doubles is 2 or more, so 253 + 1 = 9,007,199,254,740,993 rounds to 9,007,199,254,740,992. JavaScript calls 253 − 1 Number.MAX_SAFE_INTEGER.

What are the limits of double precision?

The largest finite double is about 1.7976931348623157 × 10308, the smallest normal 2.2250738585072014 × 10−308, and the smallest subnormal 2−1074 ≈ 4.94 × 10−324. Machine epsilon is 2−52 ≈ 2.22 × 10−16.

Sources

  • IEEE Std 754-2019, IEEE Standard for Floating-Point Arithmetic, IEEE, 2019 (revision of IEEE 754-2008 and IEEE 754-1985).