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 06 '26
How about this: https://gist.github.com/MineFartS/601e8f5e5d17e3e5316978a72fab3b40