When 7110 fails equality but 7120 passes: floating-point nightmare in the console
Description
The image shows a dark-themed developer console with two REPL evaluations rendered in monospaced light-green text against a charcoal background. First line: “7110 / 100 * 100 == 7110”, followed by the console output “false” in lavender, implying the expression unexpectedly fails. A horizontal divider separates the second snippet: “7120 / 100 * 100 == 7120”, whose output is “true” in the same lavender hue, indicating the comparison succeeds. The meme highlights the classic floating-point precision pitfall - binary representation of 71.1 leads to 7109.999… so strict equality fails, while 71.2 happens to round back to 7120. It pokes fun at language quirks (particularly JavaScript but applicable elsewhere) and the subtle bugs that arise when developers naïvely compare non-integer calculations for exact equality
Comments
43Comment deleted
7110 ≠ 7110 but 7120 == 7120 - turns out IEEE-754 is Schrödinger’s accountant: your cents exist only until you ask for an audit
After 20 years in the industry, you'd think I'd remember that 0.1 + 0.2 !== 0.3, but here I am debugging why our financial calculations are off by fractions of pennies, realizing someone used regular floats for currency and now we owe the rounding errors a yacht
Floats: where x/100*100 === x is true with probability that itself can't be represented exactly
Ah yes, the classic '7110 problem' - where your code is mathematically correct but IEEE 754 decides to gaslight you. It's the programming equivalent of asking 'does (x/100)*100 equal x?' and having the universe respond 'well, that depends on what your definition of x is.' Senior engineers know this is why we have epsilon comparisons and why junior devs learn the hard way that === is a lie when floats are involved. The real kicker? 7120 works fine, making this the perfect Heisenbug to leave in production and watch your team debug at 3 AM
IEEE 754: algebra with feature flags - 7110/100*100 !== 7110, 7120/100*100 === 7120. This is why money lives in ints, not hope
Floats' roundtrip diet: 710 divides, multiplies back 10 units lighter - exact revenge for using them in prod math
Comparing floats with === is how you unit-test IEEE-754 instead of your code
rounding Comment deleted
Js shits Comment deleted
that's not js fault Comment deleted
Well it's JS that has no int type Comment deleted
It has BigInt Comment deleted
As a primitive type bruh Comment deleted
WE'VE GOT YOU SURROUNDED COME GET YOUR 0.1+0.2 0.30000000000000004ED Comment deleted
Everyone who compares floats by exact match - should be sterilized. Comment deleted
Oh, really? Comment deleted
yea, give me your hands, they are unclean after that code Comment deleted
ong Comment deleted
What is the right way to do then? Comment deleted
|float1 - float2| < precision Comment deleted
yup Comment deleted
I see. Then you don’t even need to round it to integer. Comment deleted
that's not the problem, the problem is people calculating with floats and then not rounding to integers afterwards and/or just calculating with ints from the beginning. Comment deleted
Compared two numbers. A float and an integer. What is wrong here? Comment deleted
are you trolling or something? Comment deleted
Reeep Comment deleted
Ah that rounding errors reep Comment deleted
Jokes about float numbers in 2022? Rly? Comment deleted
waaait, idk js, but isn't === comparing obj IDs Comment deleted
that's… a good question, actually. Imma try it out Comment deleted
nope, dunno what the difference between == and === is Comment deleted
Isn't === supposed to not only compare expression values like == does, but also their types (in loosely-typed languages)? Comment deleted
seems like it Comment deleted
yeah Comment deleted
Just JS things Comment deleted
*CPU things Comment deleted
*IEEE 754 things Comment deleted
There's Python3 example ITT. Just float things Comment deleted
Hehhe float Comment deleted
JSON won't parse into BigInt Comment deleted
Write parser which parses into BigInt Comment deleted
Thanks, will do it as soon as never Comment deleted
https://www.npmjs.com/package/json-bigint here you go Comment deleted