2 ms·
Floats can do it. Do your computation, and then check the inexact flag.
by moonchild 3y ago
Floats can do it. Do your computation, and then check the inexact flag.
- PhilipRoman 3y agoTIL such a thing exists. Although it seems like it is rarely used; there is some discussion here https://cs.stackexchange.com/questions/152373/what-are-the-use-cases-for-the-ieee-754-inexact-flag https://cs.stackexchange.com/questions/152373/what-are-the-u... I guess most practical calculations would end up triggering the inexact flag.
- moonchild 3y agoFloats can represent all integers with magnitude <=2^53. Which is a sight smaller than integers, under the standard representation (magnitude <2^62), but still plenty for most applications—the point is to use this to implement integer math, not float math. That covers multiplication, addition, and subtraction; div/mod is admittedly a bit trickier, though it's a doozy with avx512. (There's also a cute consequence: you can construct numbers outside the contiguous range of representable integers; so long as you never incur any rounding error, the result will be correct, and the inexact flag will not be set.)
- deleted 3y ago[deleted]