How it’s calculated
Computers store most non-whole numbers in IEEE 754 binary floating point, a binary version of scientific notation. A pattern has three fields: a sign bit (0 positive, 1 negative), a biased exponent and a fraction (mantissa). For normal numbers the significand is 1.fraction in binary, with the leading 1 not stored (the hidden bit).
- 32-bit single precision (float): 1 sign bit, 8 exponent bits (bias 127), 23 fraction bits.
- 64-bit double precision (double): 1 sign bit, 11 exponent bits (bias 1023), 52 fraction bits.
Most decimals, such as 0.1, have no exact binary form, so they are rounded to the nearest pattern (ties go to the one ending in 0). The calculator shows the exact value that is stored and the rounding error. As a 32-bit float, 0.1 is stored as 0x3DCCCCCD = 0.100000001490116119384765625, an error of +1.490116119384765625 × 10⁻⁹.
Example (decoding): 0xC1B40000 is 1 | 10000011 | 01101000000000000000000. The sign is negative, the exponent field is 131 so the power is 2^(131 − 127) = 2⁴ = 16, and the significand is 1.01101₂ = 1.40625. The value is −1.40625 × 16 = −22.5.
Frequently asked questions
Why is 0.1 + 0.2 not exactly 0.3 on a computer?
None of the three numbers is exact in binary. As doubles, 0.1 and 0.2 are both stored slightly too large, and their sum rounds to 0.30000000000000004, which is a different double from the one nearest 0.3.
How many decimal digits does a float or double hold?
A 32-bit float has a 24-bit significand, about 7 significant decimal digits. A 64-bit double has 53 bits, about 15 to 17 digits. Integers are exact up to 2²⁴ = 16,777,216 in a float and 2⁵³ = 9,007,199,254,740,992 in a double.
What is a subnormal (denormal) number?
When the exponent bits are all 0, the hidden leading 1 is dropped and the power of 2 is fixed at its minimum, so numbers can shrink gradually toward zero instead of jumping straight to it. The smallest positive float is 2⁻¹⁴⁹ ≈ 1.4 × 10⁻⁴⁵.
What do infinity and NaN mean?
An exponent field of all 1s is reserved. With a zero fraction it means ±infinity, the result of overflow or 1 ÷ 0. With any other fraction it is NaN, short for “not a number”, the result of 0 ÷ 0 or the square root of a negative number.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
- Dive Into Systems, §4.8 Real Numbers in Binary (IEEE 754 single precision, decoding −22.5) — Dive Into Systems (Matthews, Newhall & Webb; West Point and Swarthmore College), free online textbook
- What Every Computer Scientist Should Know About Floating-Point Arithmetic (Goldberg), Tables D-1 and D-2: IEEE 754 format parameters and special values — Oracle (reprint of the ACM Computing Surveys paper)
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator