Floating-point anatomy
About this app
Sign, exponent, mantissa — clickable bit by bit, with the exactly decoded value. The number line shows every representable number as a tick: the gaps double at each power of two. Store 0.1 and see the rounding error — and the demo panel recomputes 0.1 + 0.2 ≠ 0.3 in the mini format.
Anatomy of a floating-point number
IEEE 754 floating-point numbers consist of three fields: a sign bit s, an exponent e and a mantissa m. The value is (−1)^s · 1.m · 2^e, and the leading 1 is not stored. Because the mantissa has only finitely many bits, only a finite set of numbers can be represented. Every interval between two powers of two holds the same count of representable numbers, so the gaps double at each power of two. Numbers such as 0.1 have infinitely many binary digits and are rounded to the nearest representable value.
What the app shows
A bit field with clickable tiles for sign, exponent and mantissa, and below it a formula line with the decomposition and the exactly decoded value. A number line draws every representable number of the chosen format as a tick and marks the stored value and the input. You can pick the mini formats 1|3|3 and 1|4|3 or the 16-bit format 1|5|10. A demo panel works through 0.1 + 0.2 in the active format step by step.
Try it yourself
Flip single bits and read off the value, or type a decimal number and store it: the app shows the stored value and the rounding error. Compare how dense the ticks are near zero and how far apart they are for large numbers. Then store 0.1 and open the demo panel: it shows which representable number the sum 0.1 + 0.2 lands on and where the rounded 0.3 lies.
Frequently asked questions
- Why is 0.1 + 0.2 not exactly 0.3?
- 0.1 and 0.2 have infinitely many binary digits and are rounded when stored. The sum of the two rounded values lands on a different representable number than the rounded 0.3. With 64-bit floating point, 0.1 + 0.2 therefore gives 0.30000000000000004.
- What are sign, exponent and mantissa?
- The sign bit says whether the number is positive or negative. The exponent sets the magnitude as a power of two and is stored with a bias. The mantissa holds the fraction bits after the leading 1 and determines the precision.
- Why do the gaps between floating-point numbers grow?
- Each interval between two powers of two contains the same number of representable values, 2 to the power of the mantissa bits. If the interval is twice as long, each gap is twice as large too. The relative precision therefore stays roughly constant.
- Which formats can I try in the app?
- Two mini formats with 7 and 8 bits (1|3|3 and 1|4|3) and the 16-bit half format 1|5|10. In each one you can flip bits, store decimal numbers and read the rounding error.
Subject: Computer science
More from Computer science
- Ackermann function
- Elevator simulator
- Binary workshop
- Binary versus linear search
- The Collatz problem
- Inside a CPU
- Swap the inside
- One frame in 16 milliseconds — how a game engine renders an image (3D)
A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps