Lesson 03 — IEEE 754 Floating-Point

1. Float32 Bit Builder — 32 toggle bits

Bấm vào bất kỳ bit để toggle 0↔1. Xem kết quả decode real-time. Màu: đỏ = sign · xanh = exponent · xanh lá = mantissa.

Sign (1 bit)
Exponent (8 bit)
Mantissa (23 bit)
= ?

2. Decimal → IEEE 754 Converter (step-by-step)

Nhập số và bấm Encode...

3. Bẫy 0.1 + 0.2 — bit-level proof

Tại sao 0.1 + 0.2 ≠ 0.3? Xem biểu diễn bit chính xác của từng số:

float64: 0.1

...

float64: 0.2

...

float64: 0.1 + 0.2

...

float64: 0.3 (literal)

...

4. float32 vs float64 — precision side-by-side

5. Catastrophic Cancellation Demo

Nhập hai số lớn gần nhau. Xem sai số khi trừ bằng float32 vs float64.

6. Bảng giá trị đặc biệt IEEE 754

Bit pattern (E, M)TênGiá trị float32Ghi chú
E=0, M=0, S=0+00x00000000+0 == −0 nhưng 1/+0 = +Inf
E=0, M=0, S=1−00x800000001/−0 = −Inf
E=0, M≠0Denormal±(0.M)×2⁻¹²⁶Lấp đầy khoảng gần 0
E=255, M=0, S=0+Infinity0x7F800000Overflow, 1/+0
E=255, M=0, S=1−Infinity0xFF800000Log(0), 1/−0
E=255, M≠0NaN0x7FC00000 (quiet)0/0, sqrt(−1), Inf−Inf
1≤E≤254Normal(−1)ˢ×1.M×2^(E−127)Phần lớn số thực