Compare Floats Before You Round

Compare Floats Before You Round
floating-point-memes, comparison-bug-memes, thermostat-memes, iot-memes, programming-error-memes | ProgrammerHumor.io

Nothing says "I'm a competent programmer" like waking up at 3:25am to an emergency alert that 72 is dangerously higher than... 72.

Classic floating point comparison fail. Somewhere in that thermostat's code, 72.0001 is being compared to 72 with the == operator instead of a proper threshold check. The developer who wrote this is probably the same person who thinks SQL injection is just a fancy way to administer medicine.

Future archaeologists will find this thermostat and conclude our civilization collapsed because we couldn't figure out that 72.00000001 ≈ 72.

More Like This