4 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 2y 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.
- eterm 2y 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.")
- adrian_b 2y agoUnchecked integer overflow strikes again.
- rhaps0dy 2y agoOh no, Pytorch does the same thing: a = torch.tensor(-2*31, dtype=torch.int32) assert a == a.abs()
- MawKKe 2y agonumpy as well. and tensorflow
- winstonbwillis 2y ago[dead]
- bobbylarrybobby 2y agoRust does the same in release, although it panics in debug.