r/computing • u/philtrondaboss • Jan 31 '26
Function to safely perform Floating Point Operations (FLOPs)
https://gist.github.com/MineFartS/3764b1e5abff431831e743c302503396I quickly made this function to perform flops without the rounding bug. It's uses a little more resources than a normal flop, but it gets the job done more reliably.
EXAMPLE:
>>> .1 + .2
0.30000000000000004
>>> safe_flop(.1, '+', .2)
.3
1
Upvotes
View all comments
Show parent comment
1
u/philtrondaboss Feb 01 '26
Possibly, but it would require more hard-coding. I prefer soft-coding wherever possible.