Skip to content
DevMeme
5149 of 7435
Batman slaps clarity into the floating-point precision vs accuracy debate
CS Fundamentals Post #5636, on Nov 5, 2023 in TG

Batman slaps clarity into the floating-point precision vs accuracy debate

Description

Classic “Batman slapping Robin” comic panel with a red background. Robin (left) says in a speech bubble: “FLOATING-POINT MATH CAUSES LOSS IN PRECISION”. Batman (right) smacks him mid-sentence and replies in a second bubble: “...IN ACCURACY”. The meme highlights the well-known numerical nuance that floating-point operations reduce accuracy because of limited precision bits, a distinction veterans of numerical computing often police. The humor resonates with engineers who have debugged mysterious 0.1 + 0.2 ≈ 0.30000000000000004 bugs and endured code reviews correcting misuse of “precision” versus “accuracy.”

Comments

23
Anonymous ★ Top Pick When product says “just round to two decimals,” I hear Batman winding up his backhand
  1. Anonymous ★ Top Pick

    When product says “just round to two decimals,” I hear Batman winding up his backhand

  2. Anonymous

    After 20 years of explaining to junior devs why 0.1 + 0.2 !== 0.3, you realize the real loss isn't in precision OR accuracy - it's in your faith that anyone actually reads IEEE 754 before implementing financial calculations with doubles

  3. Anonymous

    Ah yes, the eternal struggle: explaining to stakeholders why 0.1 + 0.2 ≠ 0.3 isn't a bug in your code, it's a feature of IEEE 754. Batman here is technically correct - the best kind of correct - because floating-point math doesn't lose *precision* (the number of significant digits remains constant), it loses *accuracy* (the ability to represent exact decimal values in binary). This is why senior engineers reach for Decimal types when handling money, use epsilon comparisons for equality checks, and develop a Pavlovian response to seeing floating-point arithmetic in financial code. The real tragedy? After 20 years, you'll still encounter production bugs from developers who think '==' is appropriate for comparing doubles

  4. Anonymous

    Batman gets it: floats aren't imprecise - they're precisely why BigDecimal was invented, and we still forget to use it in prod

  5. Anonymous

    Precision is a constant (mantissa bits); accuracy dies when you subtract near-equals at scale - otherwise known as the moment finance says, “just use float.”

  6. Anonymous

    Floating point keeps its 53 bits of precision - accuracy gets slapped the moment you subtract near-equals; Kahan is the only one trying to break up the fight

  7. @mihanizzm 2y

    What's the difference?

    1. @decide_later 2y

      the number of digits you can store vs. how well you can store them but yeah, these terms seem pretty interchangeable

      1. @mihanizzm 2y

        ty

    2. @pztrn 2y

      You may store 100 digits successfully (precision), yet still you get 0.1+0.2=0.30000000000000004 (accuracy).

  8. @decide_later 2y

    there should be a reason why programmers dealing with money (in banking or fintech) seem to prefer using integers and fixed-point numbers for that, after all

    1. @sylfn 2y

      please dont use i32 for money...

      1. @Vlukyane 2y

        Why not?

        1. @sylfn 2y

          too smol

  9. @mihanizzm 2y

    But are there no any connection between two of these terms? Like, you can improve your calculation accuracy by improving it's precision?

    1. @decide_later 2y

      to some extent, yeah, but this won't help you if your algorithms are flawed and have high margin of error, or you're not careful with rounding or comparison that notorious issue with 0.1 + 0.2 being equal to 0.30000004 happens because 0.1 is a repeating decimal in base 2 and there is some flawed rounding going on when switching between bases and storing numbers

      1. @mihanizzm 2y

        I got it now, thank you!

  10. Pavel 2y

    The best explanation I'v found at https://stackoverflow.com/a/41788677 is Precision is the number of digits you specify, while accuracy specifies the difference from the true result. To give an example: 3.14 is less precise than 3.149 but more accurate if it is considered the value of pi.

  11. @SamsonovAnton 2y

    In time keeping, they use theese three terms: • resolution — smallest unit of scale that can be expressed, i.e. 1 nanosecond; • precision — smallest unit of increment of particular clock device, i.e. 25 nanoseconds; • accuracy — deviation of particular clock from some reference, i.e. 400 microseconds.

  12. @purplesyringa 2y

    billionaire... in hundredths of cents?

  13. @callofvoid0 2y

    precision : spread accuracy : deviation

  14. @endisn16h 2y

    how i piss on different stages of being drunk

    1. @RiedleroD 2y

      drunk | defiant --------|------------ normal | on ritalin

Use J and K for navigation