`checked_add` and friends for floats?

I was looking for a replacement for checking errno after pow() in C and came across the num crate which needs CheckedMul for overflowing_pow to be a available. Is this something that was rejected due to libm/other issues or simply never got done?

I haven't seen any discussion of this.

To me the biggest problem is what checked_add would even mean for floats. Arithmetic on floats starts to "fail" due to rounding errors long before they hit their absolute maximum value. For some values x + 1 == x. Should that fail? But that is the same problem as 0.1 + 0.2 != 0.3, just with an arbitrarily larger error bound.

There are certainly edge cases that make the desired behavior debatable. Personally, if we were going to have checked operations for floats, I would only want them to check for inf/nan.

1 Like