News for hackers. Stuff that matters.
Re:One does not simply calculate the absolute value by kmm on Sunday August 22, 2021 @03:26PM (#28268656)
Which languages did you try? I found that dividing 1.0 by 0.0 gives Infinity in Java, C, Julia, JavaScript, Ruby, Clojure, Haskell and Rust. I get division errors in Python and Perl.

Curiously, Go gives me a compiler error if I divide constant literals, but assigning 0.0 to a variable and dividing by it does work. On top of that, assigning -0.0 to a float variable leads to it having the value +0.0, which I would call a borderline compiler bug. Both are probably a consequence of Go constant literals not being IEEE-754 floats but some arbitrary precision number types, but it's very unexpected behavior.

Re:One does not simply calculate the absolute value by da_chicken on Sunday August 22, 2021 @03:42PM (#28268821)
> Which languages did you try?

Python and C#.

Re:One does not simply calculate the absolute value by kmm on Sunday August 22, 2021 @03:57PM (#28268993)
Dividing 1.0 by 0.0 gives ∞ in C# as well when I try it.
Re:One does not simply calculate the absolute value by da_chicken on Sunday August 22, 2021 @04:03PM (#28269042)
You're right. I must've divided 0 by 0 and -0. That's the only way C# gives me NaN. I thought I'd specifically avoided doing that.
Re:One does not simply calculate the absolute value by Kranar on Sunday August 22, 2021 @03:56PM (#28268978)
Python does throw an exception but C# does not.