Floating point, briefly
What it is
float64 holds about 15-16 significant decimal digits, float32 about 7. Values are spaced logarithmically, so adding a small number to a large one can change nothing at all.
Why it matters
It is why 0.1 + 0.2 != 0.3, why summing a million small floats loses accuracy, and why a float32 accumulator of a long sum can stall entirely.
In the real world: Why 0.1 + 0.2 isn't exactly 0.3, and why money is often stored in whole paise or cents in payment systems.
0.1 + 0.2 == 0.3 # False
np.isclose(0.1 + 0.2, 0.3) # True — the right comparison
np.float32(1e8) + np.float32(1.0) == np.float32(1e8) # True: 1.0 vanished
np.arange(1e6, dtype=np.float32).sum() # noticeably off; pass dtype=np.float64Comparing floats with ==, including against a value you just computed. Use np.isclose or np.allclose, with atol set deliberately when the numbers can be near zero.
Practise it: Running Share of a Total