top | item 43491079

(no title)

jffhn | 11 months 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.

discuss

order

eterm|11 months ago

You 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|11 months ago

Oh no, Pytorch does the same thing:

a = torch.tensor(-2*31, dtype=torch.int32) assert a == a.abs()

MawKKe|11 months ago

numpy as well. and tensorflow

adrian_b|11 months ago

Unchecked integer overflow strikes again.

bobbylarrybobby|11 months ago

Rust does the same in release, although it panics in debug.