this post was submitted on 17 May 2025
58 points (93.9% liked)
Programmer Humor
35694 readers
200 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Definitionally in IEEE floating point, NaN is not equal to anything, including itself. The only real abomination here is B:
I mean, B does make some amount of sense, if you realize that it's supposed to give you the maximum among the parameters (so you'd normally call it as
Math.max(5, 3) === 5
).Well, and you can call that with zero parameters, because you can spread an array into it, which might have zero length. And then given these conditions, and if you don't want to throw an error, then
-Infinity
is kind of the least bad remaining option, as it's likely to generally work with the rest of your logic.