Skip to content
DevMeme
1955 of 7590
Bugs Post #2175 · source on Telegram

JavaScript's Unique Approach to Basic Arithmetic

Description

This meme uses the 'Woman Showing Paper to a Cat' format. The top part of the image contains a text exchange: 'Teacher: How much is 1.1 * 3 ?', 'He: 3.3', 'Teacher: Then why did you write 3.3000000000000003 ?'. The bottom panel shows a woman looking at a paper with a small grey cat, and a zoomed-in image of the cat looking stressed and guilty. The cat is labeled 'JavaScript developer'. The humor stems from a well-known quirk in JavaScript (and other languages using IEEE 754 floating-point arithmetic) where simple decimal calculations result in precision errors. The expression `1.1 * 3` evaluates to the long decimal because of how these numbers are represented in binary. The meme personifies this language flaw as a developer being caught making a fundamental math error, perfectly capturing the frustrating and often comical nature of floating-point inaccuracies

Comments

28
Anonymous ★ Top Pick This is why we have a `===` operator. One equals is for the value, one is for the type, and the third is to check if the floating-point representation is having an existential crisis
  1. Anonymous ★ Top Pick

    This is why we have a `===` operator. One equals is for the value, one is for the type, and the third is to check if the floating-point representation is having an existential crisis

  2. Anonymous

    PM: “Can we stop showing 3.3000000000000003 on the invoice?” Me: “Sure - just budget a sprint to replace IEEE-754, every browser VM, and probably a few laws of physics.”

  3. Anonymous

    After 20 years in the industry, you learn that the real skill isn't avoiding floating-point errors - it's explaining to the finance team why their quarterly reports are off by 0.0000000000000003 cents and convincing them it's actually the computer being mathematically correct

  4. Anonymous

    Every JavaScript developer has had that moment explaining to a stakeholder why their financial calculations are off by 0.0000000000000003. 'It's not a bug, it's IEEE 754!' we cry, while frantically googling decimal.js libraries and wondering why we didn't just use integers and store everything in cents like the backend team suggested three sprints ago

  5. Anonymous

    I didn’t fail math - I passed IEEE‑754: 3.3 is a UI concern; 3.300000000000003 is the backend truth

  6. Anonymous

    In JavaScript, 1.1*3 equals an IEEE‑754 footnote, a decimal library, and an awkward finance call

  7. Anonymous

    Because JS multiplies like microservices: distributed accuracy with consistency eventually

  8. @lord_nani 5y

    why exclusively js?

    1. @metal_Dash 5y

      Yes

  9. @maxgraey 5y

    https://0.30000000000000004.com/

    1. @doorhinge 5y

      brilliant

  10. @maxgraey 5y

    When you hate JS for 0.1+0.2 != 0.3 you should in the same way hate Rust, C++, python, Haskell, your CPU and at last William Kahan)

    1. @asm3r 5y

      +1.

  11. @ynsgnr 5y

    Floating point errors are really something

  12. @zherud 5y

    is there a language where 1.1*3 is actually 3.3?

    1. Deleted Account 5y

      haskell and lisp

      1. Deleted Account 5y

        they use fractions and floats

      2. @zherud 5y

        and how are there 1.1*3=3.3?

      3. @bit69tream 5y

        common lisp (sbcl) * (* 1.1 3) 3.3000002 haskell Prelude> 1.1 * 3 3.3000000000000003

        1. Deleted Account 5y

          if you do the 11 % 10

          1. @bit69tream 5y

            ?

            1. Deleted Account 5y

              represent 1.1 as rational

              1. @bit69tream 5y

                * (float (* (rationalize 1.1) 3)) 3.3

        2. Deleted Account 5y

          ye like this it's gonna produce trash

        3. @asm3r 5y

          Sbcl: (/ 3 10) 3/10

    2. @Araalith 5y

      Even IRL 1.1*3 can be 3.2999(9)

  13. @dr_f33lg00d 5y

    python kek

  14. @firs_iln 5y

    fukkk whyyy

Use J and K for navigation