News for hackers. Stuff that matters.
Re:Three-Valued Logic by dagw on Friday December 15, 2017 @06:47AM (#15931164)
looking at you, javascript NaN

That's not a JavaScript thing, it's an IEEE 754 floating point standard thing and is the same in every programming language that implements that standard (which is basically all of them). But for some reason only JavaScript developers seem to be bothered by this.

Furthermore IEEE 754 floating point numbers don't have many properties that you'd expect from 'real' numbers. For example addition is not always associative and the distributive law does not always hold.

Re:Three-Valued Logic by schindlabua on Friday December 15, 2017 @06:23PM (#15936155)
I understand the motivation but I disagree that NaN should not equal NaN. The es docs even explicily mention that "to ECMAScript code, all NaN values are indistinguishable from each other."

I'm writing javascript and I don't want to need to care about IEEE 754 floating point (all I know about is `Number` anyway).

If you compare two NaNs in C that happen to have the same binary representation, they are equal. Which means that a typical javascript runtime will need to check for that case, no? So if they have to make the decision between making all NaNs equal or unequal, and there's going to be a runtime check either way, why not make NaN == NaN and save us a headache?

Re:Three-Valued Logic by vorotato on Friday December 15, 2017 @09:29AM (#15932016)
it's because javascript is unityped.
Re:Three-Valued Logic by sgustard on Friday December 15, 2017 @12:19PM (#15933315)
var x; 0+x => NaN is the gateway to frustration.