Alterna · учебный материал
IEEE 754: single and double
IEEE 754: float32 and floath64 details. Single+doble calculator, special values (NaN, Inf, denormalized), comparison of types.
Что в этом материале
- Structure IEE 754
- Single calculator and double with bit chart
- Special IEEE 754
- Loss of precision: single vs double
- Mini-test: 5 questions
Содержание и основные понятия
Back to the table of contents
Alterna · Chapter 30 · page 30.2
IEEE 754: single and double
Standard for the representation of physical numbers: detailed, calculator, bit visualizer and special values.
IEEE 754
It's a standard that all modern CPU/GPU are working on. The numbers are stored in the form of a sign, a displaced order, and a mantis, which gives a huge range at the cost of accuracy.
GEF
PIF
EGE No. 14
He's got a little bit of depth.
01
Structure IEE 754
Sign, order, mantis.
The material number shall be stored in the form of:
(−1)
s
× 1.M × 2
(E−bias)
where s is the sign, M is the fractional part of the mantis (always 1.M, since the mantissa is normal), E is the stored order with the displacement.
float32 (32 bits)
s
8 bits
Mantiss (23 bits)
1 bit
bias=127
hidden 1 not stored
= 32 bits
Single (float32, 32 bits)
Sign s:
1 bit
Order E:
8 bits
(bias = 127)
Mantissa M:
23 bits
Accuracy: ~7 decimal digits
Range: ~10
±38
Double (float64, 64 bits)
Sign s:
1 bit
Order E:
11 bits
(bias = 1023)
Mantissa M:
52 bits
Accuracy: ~15 decimal digits
Range: ~10
±308
Hidden unit
Because the first figure is a normalized binary mantis.
always 1
(e.g. 1,10012), it is not stored, it's a hidden bit.
02
Single calculator and double with bit chart
🔬
Interactive 1: Number of IEEE 754 (single + double) with colour markings
Decimal
Single (32 bits):
Sign
Order
Mantissa
Введи число и нажми «Перевести».
03
Special IEEE 754
The clicks on the card -- you see the bit chart.
⚡
Interactive 2: Special Value Visualizer (NaN, Inf, denorm, ±0)
Bit chart (32 bits):
04
Loss of precision: single vs double
Make sure: 0.1 + 0.2 ~ 0.3
⚖️
Interactive 3: Comparison of Single vs Double — Accuracy
A
Operation
B
Введи A, B и нажми «Вычислить».
Relative error of single:
That's right.
7 digits
greater error
Classic example
0.1 + 0.2
in most languages =
0.30000000000000004
It's not a bug, it's an IEEE 754. The number of 0.1 in the binary is an infinite fraction, like one-third in the decimal. The float/double is cut to the final number of bits.
🎯
Mini-test: 5 questions
XP: 0 / 100
🧩
Quick test on the subject
Five questions, 20 XP for every correct answer.