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.”
Use J and K for navigation
Comments
23Comment deleted
When product says “just round to two decimals,” I hear Batman winding up his backhand
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
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
Batman gets it: floats aren't imprecise - they're precisely why BigDecimal was invented, and we still forget to use it in prod
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.”
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
What's the difference? Comment deleted
the number of digits you can store vs. how well you can store them but yeah, these terms seem pretty interchangeable Comment deleted
ty Comment deleted
You may store 100 digits successfully (precision), yet still you get 0.1+0.2=0.30000000000000004 (accuracy). Comment deleted
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 Comment deleted
please dont use i32 for money... Comment deleted
Why not? Comment deleted
too smol Comment deleted
But are there no any connection between two of these terms? Like, you can improve your calculation accuracy by improving it's precision? Comment deleted
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 Comment deleted
I got it now, thank you! Comment deleted
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. Comment deleted
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. Comment deleted
billionaire... in hundredths of cents? Comment deleted
precision : spread accuracy : deviation Comment deleted
how i piss on different stages of being drunk Comment deleted
drunk | defiant --------|------------ normal | on ritalin Comment deleted