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/emeraldscorpion Feb 01 '26
I would agree with you in the general case, but not when it comes to eval