6 ms·
>Though abs() returning negative numbers is hilarious. Math.abs(Integer.MIN_VALUE) in Java very seriously returns -2147483648, as there is no int for 214748364
by jffhn 1y ago
>Though abs() returning negative numbers is hilarious.
Math.abs(Integer.MIN_VALUE) in Java very seriously returns -2147483648, as there is no int for 2147483648.
- adrian_b 1y agoUnchecked integer overflow strikes again.
- eterm 1y agoYou inspired me to check what .NET does in that situation. It throws an OverflowException: ("Negating the minimum value of a twos complement number is invalid.")
- rhaps0dy 1y agoOh no, Pytorch does the same thing: a = torch.tensor(-2*31, dtype=torch.int32) assert a == a.abs()
- MawKKe 1y agonumpy as well. and tensorflow
- winstonbwillis 1y ago[dead]
- bobbylarrybobby 1y agoRust does the same in release, although it panics in debug.