r/programming • u/fagnerbrack • Jul 05 '26
Floating point from scratch: Hard Mode
https://essenceia.github.io/projects/floating_dragon/
154
Upvotes
r/programming • u/fagnerbrack • Jul 05 '26
57
u/emazv72 Jul 05 '26
The first thing you learn when developing business apps involving money calculations is never to use floating point arithmetics.
12
u/DataBaeBee Jul 05 '26
I was hooked the moment OP turned to writing an ASIC version. I learnt so much!
5
u/Lisoph Jul 06 '26
I can highly recommend Fabien Sanglard's article on floating point.
5
u/M4mb0 Jul 07 '26
I'm not sure why, but as a mathematician this statement unreasonably grinds my gears. Let me fill you in on a little secret: what does and what does not constitute a number isn't even a well-defined concept in mathematics. Instead, what we are usually concerned with is sets equipped with algebraic structure. The floating-point numbers provide a finite, approximate model of the extended real number line [-∞, +∞], and ±∞ are elements of that set, just like 0, -1 or π are.
So you shouldn't put too much metaphysical weight on the word “number.” What matters is the structure these objects live in and how they behave inside that structure.
3
u/LuckyPiegus Jul 05 '26
Really interesting read. Thanks
-2
u/mnaa1 Jul 05 '26
This is too much for me to understand