Floating-Point Explorer
See how IEEE-754 half/single/double store a number: bits, exact value, ULP, rounding error.
How it works
Shows the sign, exponent and fraction bits of a decimal number in IEEE-754 binary16, binary32 or binary64, the exact decimal value that is actually stored (computed with big integers), the rounding error, the ULP and the neighbouring representable numbers. Evaluates expressions such as 0.1 + 0.2 step by step and explains subnormals, infinities and NaN.
- Decimal input is parsed as an exact fraction and rounded to the nearest representable value of the chosen format (round half to even), with big-integer arithmetic, so there is no double rounding via JavaScript numbers.
- A normal number is (−1)^sign × 1.fraction × 2^(exponent − bias); subnormals (exponent field 0) are (−1)^sign × 0.fraction × 2^(1 − bias). The exact decimal of the stored value always terminates because the denominator is a power of two.
- ULP is the gap to the next representable number away from zero; the neighbours are the bit patterns ±1 (crossing between ±0 and the smallest subnormals).
- Expressions are evaluated twice: exactly with fractions, and in the chosen format with rounding after every literal and every operation (IEEE-754 semantics, like JavaScript for binary64 or C float for binary32).
Sources
- IEEE 754-2019: Standard for Floating-Point Arithmetic (IEEE)
- Goldberg, D. (1991): What Every Computer Scientist Should Know About Floating-Point Arithmetic (ACM Computing Surveys 23(1))
Use this tool in an app
These free programs for your browser have this tool built in, next to everything else the task needs.
-
Proofline Math notebook
Solve, graph, test and visualise in one notebook — with data, findings and a report.
Related tools
- Number-Theory Lab – Primality, factorisation, gcd, modular arithmetic, CRT, φ, π(n), Collatz, continued fractions.
How to use the Floating-Point Explorer
See exactly how a number is stored in IEEE-754 half, single or double precision: bits, exact decimal value, rounding error, ULP and neighbours.
What it is for
Every programmer meets 0.1 + 0.2 = 0.30000000000000004 sooner or later, along with its cousins: a float counter that stops increasing, money totals off by a cent, or comparisons that fail for no visible reason. They all come from the same fact. Binary floating point can only store fractions whose denominator is a power of two, so most decimals are rounded on input and after every operation.
This explorer shows that rounding precisely. Enter a decimal, an expression such as 0.1 + 0.2, a special value (NaN, Infinity) or a bit pattern (0x…, 0b…). Choose binary16 (half), binary32 (float) or binary64 (double), and you get the sign, exponent and fraction bits, the exact decimal value that is stored (computed with big integers), the rounding error, the ULP and the two neighbouring representable numbers.
Worked example
0.1 + 0.2 in binary64: "evaluates to 0.30000000000000004 (exactly 0.3000000000000000444089209850062616169452667236328125); the exact result is 0.3."
The step table shows why. 0.1 is stored as 0.1000000000000000055511…, 0.2 as 0.2000000000000000111022…, and their sum rounds to the double just above 0.3. The double nearest to 0.3 is a different one, 0.29999999999999998889776975…, so 0.1 + 0.2 == 0.3 is false. The ULP at this size is about 5.55 × 10⁻¹⁷, and the result is exactly one ULP away from the correctly rounded 0.3.
16777217 in binary32: stored as 16777216, error −1, ULP 2. Above 2²⁴ a float can only represent even integers. A float counter incremented by 1 gets stuck at 16,777,216. In binary64 the same number is exact (0x4170000010000000).
0x0001 in binary16: the smallest positive half-precision subnormal, exactly 0.000000059604644775390625. The tool warns that subnormals have fewer than 11 significant bits.
How to read the result
- Bits / hex: the raw encoding, split into sign, exponent field and fraction field.
- Unbiased exponent: the power of two after subtracting the bias (15, 127 or 1023).
- Stored exact: the true value of the stored bits. It always terminates, because the denominator is a power of two.
- Shortest: the shortest decimal that reads back to the same bits. This is what most languages print.
- Rounding error / relative error: stored minus input. The relative error of a normal number is at most half an ULP relative to its size (about 1.1 × 10⁻¹⁶ for doubles).
- ULP and neighbours: the gap to the next number and the values just below and above.
- Other formats: the same input in all three precisions side by side.
Tips and common mistakes
- Never compare floats with
==after arithmetic. Compare with a tolerance scaled to the magnitude, or use integers. - Store money in integer cents or a decimal type. 0.1 euro has no exact binary representation in any precision.
- The ULP grows with magnitude. For doubles, the gap around 10¹⁶ is 2, so adding 1 to 10¹⁶ does nothing.
- Half precision (binary16) runs out quickly: its largest finite value is 65504, and 16777217 becomes Infinity.
- Expressions are rounded after every literal and every operation, just like JavaScript (binary64) or C
float(binary32). Changing the order of additions can change the result.
FAQ
Why is 0.1 not exact?
0.1 = 1/10, and 10 contains the factor 5, which a power-of-two denominator can't represent. The binary expansion repeats forever and has to be rounded.
What is a ULP?
"Unit in the last place": the distance from a number to the next representable number away from zero. It's the natural unit for measuring floating-point error.
What are subnormal numbers?
Values smaller than the smallest normal number, stored with exponent field 0. They fill the gap to zero gradually, at the cost of precision.
Does JavaScript use binary64?
Yes. JavaScript's Number is an IEEE-754 double, so the binary64 results match what a browser computes.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://floatingpointexplorer.usefulweb.site/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://floatingpointexplorer.usefulweb.site/mcp· tool namefloating_point_explorer
Example request
curl -s -X POST https://floatingpointexplorer.usefulweb.site/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"value":"0.1","format":"binary64"}'