phpc.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A server for PHP programmers & friends. Join us for discussions on the PHP programming language, frameworks, packages, tools, open source, tech, life, and more.

Administered by:

Server stats:

801
active users

@dseguy Is there a reason for this, or is it a bug?

@ramsey @dseguy I believe that nan is defined to work this way by the IEEE spec for floating point numbers. I have to say that, in my own experience, I've never found a practical situation where this property helped anything in code

@ramsey @dseguy FWIW, I wouldn't be surprised if @wez is right.

JavaScript shouldn't be taken as an example of a good way to do things, as a general rule... 😛

destroyallsoftware.com/talks/w

... but it does behave similarly in this particular respect.

developer.mozilla.org/en-US/do

www.destroyallsoftware.comWat

@elazar @dseguy @wez In another branch of this thread, we discussed how NaN is specific to mathematics and doesn’t make sense when considered outside that context. In maths, NaN doesn’t represent anything, so it can’t be equal even to itself.

Of course, if you only take the meaning of the phrase “not a number,” then in a programming context, things like `"some string" == NaN` and `$someObject == NaN` could be true because they’re not numbers. 😉

@ramsey @elazar @wez So, it makes sense to me, besides the initial surprise when discovering it.

I have encountered situations where ``null !== null``, on the basis that it is not a value, and can't be compared. That would not fit PHP, though.

If any bug there is, I'd say that ``INF === INF`` should not be true (as it is now), as there are different infinities (some are even bigger than others!) I'd expect it to behave like NAN.

INF is used in 10% PHP code, and NAN is 5%.

@dseguy @ramsey @elazar @wez to be pedantic: for most situations PHP arithmetic code is going to be involved with, there aren't really different infinities.

I'm not clear whether INF === INF is going to cause real-world logic errors though.

@dseguy @ramsey @elazar @wez disallowing division by zero solved about 99% of the cases :)

@dseguy it’s not a number but (almost) a string 😉

var_dump("BA".NAN."A");