zlacker

[parent] [thread] 5 comments
1. jffhn+(OP)[view] [source] 2025-03-27 07:07:17
>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.

replies(4): >>eterm+36 >>adrian+zd >>rhaps0+oO >>bobbyl+Ca2
2. eterm+36[view] [source] 2025-03-27 08:31:53
>>jffhn+(OP)
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.")

3. adrian+zd[view] [source] 2025-03-27 10:03:32
>>jffhn+(OP)
Unchecked integer overflow strikes again.
4. rhaps0+oO[view] [source] 2025-03-27 14:44:45
>>jffhn+(OP)
Oh no, Pytorch does the same thing:

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

replies(1): >>MawKKe+AB1
◧◩
5. MawKKe+AB1[view] [source] [discussion] 2025-03-27 19:36:55
>>rhaps0+oO
numpy as well. and tensorflow
6. bobbyl+Ca2[view] [source] 2025-03-27 23:24:36
>>jffhn+(OP)
Rust does the same in release, although it panics in debug.
[go to top]