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
View all comments
Show parent comment
7
u/emazv72 Jul 07 '26
The expression
0.1 + 0.2 == 0.3
returns false when the values are floating because of the mismatch between the base 10 and the floating point base 2 internal representation. Legacy business languages (e.g. Cobol) did base 10 math by default.
This is another language where numeric expressions use decimal math natively:
An interesting thing here is the C runtime implementation: the type system uses doubles to store numbers but applies fuzzy logic and dynamic rounding to make sure the upper language evaluates the expressions properly.