Hacker News new | ask | show | jobs
by exabrial 3076 days ago
Is there a reason why we can't have that as a compiler warning?
2 comments

Because it depends on the algorithms you put a float through.

Addition has a maximum accuracy of 1 LSB. Makes sense: the last bit could have been "rounded off" and 1.5+1.5 == 2 (but really 3 should have been returned).

Subtraction has unlimited error bounds (!!!). Well, I guess there's 53-bits of a double-precision float. So subtraction can theoretically create 53-bits of error.

In practice, you need to keep track of the error bounds during the runtime of the program. Its not something that can be computed at compile time. After all, addition of a positive and negative number IS subtraction. (so some subtractions are additions: with accuracy of 1LSB. While some additions are subtractions: with unlimited error bounds)

Yes you can, if your programming language supports dependent types: https://bluishcoder.co.nz/2013/05/07/ranged-integer-types-an...