Skip to content
DevMeme
3844 of 7590
Languages Post #4187 · source on Telegram

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

43
Anonymous ★ Top Pick 7110 ≠ 7110 but 7120 == 7120 - turns out IEEE-754 is Schrödinger’s accountant: your cents exist only until you ask for an audit
  1. Anonymous ★ Top Pick

    7110 ≠ 7110 but 7120 == 7120 - turns out IEEE-754 is Schrödinger’s accountant: your cents exist only until you ask for an audit

  2. Anonymous

    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

  3. Anonymous

    Floats: where x/100*100 === x is true with probability that itself can't be represented exactly

  4. Anonymous

    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

  5. Anonymous

    IEEE 754: algebra with feature flags - 7110/100*100 !== 7110, 7120/100*100 === 7120. This is why money lives in ints, not hope

  6. Anonymous

    Floats' roundtrip diet: 710 divides, multiplies back 10 units lighter - exact revenge for using them in prod math

  7. Anonymous

    Comparing floats with === is how you unit-test IEEE-754 instead of your code

  8. @Baksy93 4y

    rounding

  9. @ShiningFlames 4y

    Js shits

    1. Deleted Account 4y

      that's not js fault

      1. @UQuark 4y

        Well it's JS that has no int type

        1. Deleted Account 4y

          It has BigInt

          1. @UQuark 4y

            As a primitive type bruh

  10. Deleted Account 4y

    WE'VE GOT YOU SURROUNDED COME GET YOUR 0.1+0.2 0.30000000000000004ED

  11. @Araalith 4y

    Everyone who compares floats by exact match - should be sterilized.

    1. @elonmasc_official 4y

      Oh, really?

      1. @dugeru42 4y

        yea, give me your hands, they are unclean after that code

    2. @SinnerK0N 4y

      ong

    3. @dsmagikswsa 4y

      What is the right way to do then?

      1. @bemberstadt 4y

        |float1 - float2| < precision

        1. @dugeru42 4y

          yup

        2. @dsmagikswsa 4y

          I see. Then you don’t even need to round it to integer.

    4. @RiedleroD 4y

      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.

    5. @paul_thunder 4y

      Compared two numbers. A float and an integer. What is wrong here?

      1. @beton_kruglosu_totchno 4y

        are you trolling or something?

  12. @ShiningFlames 4y

    Reeep

  13. @ShiningFlames 4y

    Ah that rounding errors reep

  14. @zlodes 4y

    Jokes about float numbers in 2022? Rly?

  15. @neizvestnyi 4y

    waaait, idk js, but isn't === comparing obj IDs

    1. @RiedleroD 4y

      that's… a good question, actually. Imma try it out

      1. @RiedleroD 4y

        nope, dunno what the difference between == and === is

        1. @SamsonovAnton 4y

          Isn't === supposed to not only compare expression values like == does, but also their types (in loosely-typed languages)?

          1. @RiedleroD 4y

            seems like it

          2. @sashakity 4y

            yeah

  16. dev_meme 4y

    Just JS things

    1. @asm3r 4y

      *CPU things

      1. @RiedleroD 4y

        *IEEE 754 things

    2. @chupasaurus 4y

      There's Python3 example ITT. Just float things

  17. @ZgGPuo8dZef58K6hxxGVj3Z2 4y

    Hehhe float

  18. @UQuark 4y

    JSON won't parse into BigInt

    1. Deleted Account 4y

      Write parser which parses into BigInt

      1. @UQuark 4y

        Thanks, will do it as soon as never

        1. Deleted Account 4y

          https://www.npmjs.com/package/json-bigint here you go

Use J and K for navigation