r/computing • • Jan 31 '26

Function to safely perform Floating Point Operations (FLOPs)

https://gist.github.com/MineFartS/3764b1e5abff431831e743c302503396

I 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

4 comments sorted by