Quant Memo
Coding/●●●●●

Why 0.1 + 0.2 != 0.3, and how to compare floats

A reconciliation job flags a break because a computed fill price "doesn't equal" the exchange's drop-copy price:

>>> 0.1 + 0.2 == 0.3
False
>>> 0.1 + 0.2
0.30000000000000004

Explain what's happening, and write an approx_equal(a, b) that a production system could actually use. Why does it need both a relative and an absolute tolerance?

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions