this post was submitted on 05 Apr 2025
54 points (98.2% liked)

Programmer Humor

22284 readers
1533 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
top 9 comments
sorted by: hot top controversial new old
[–] call_me_xale@lemmy.zip 10 points 5 days ago (2 children)

More people need to learn to use Rational types. A pretty large majority of the numbers that people care about in real life can easily be represented by a ratio of integers, and they allow math with perfect precision.

[–] boonhet@lemm.ee 7 points 5 days ago

Or just BigDecimal or an equivalent if rational types aren't easy to use in your language (e.g if you'd have to literally enter the denominator and numerator).

[–] Quetzalcutlass@lemmy.world 3 points 4 days ago

Someone posted this article a while back that goes into more detail on some alternatives, as well as contains one of the best and most intuitive explanations of floating point that I've ever read.

[–] zerofk@lemm.ee 4 points 4 days ago (1 children)

There is a paper titled “What Every Computer Scientist Should Know About Floating-Point Arithmetic” by David Goldberg. It’s a bit theoretical, but IMO it’s a must-read for any programmer doing more than the occasional floating point calculation. It goes beyond just limited precision and rounding errors.

[–] Metostopholes@midwest.social 5 points 5 days ago

Reject modernity, return to COBOL.

[–] jxk@sh.itjust.works 2 points 4 days ago

Javascript: The result is "0.10.2"

[–] beejboytyson@lemmy.world 1 points 4 days ago
[–] rikudou@lemmings.world 2 points 5 days ago

PHP: 0.3*

* with default precision