this post was submitted on 14 Nov 2026
398 points (97.4% liked)

Programmer Humor

34196 readers
496 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] b3nsn0w@lemmy.world 49 points 3 days ago (3 children)

duh, it's part of the IEEE 754 standard. every language that handles floating point numbers has NaN handling, and in every language NaN is a float. the only reason this is brought up as a javascript thing all the time is that js doesn't have separate float and int types (aside from special structures like typed arrays and dataviews), it just defaults to float64 for simplicity and calls it number, which lines up with the "NaN is a number? nani???" joke.

you don't like it? consult the sorry excuse of thinking sand in the device you're reading this on, because this is etched straight into it. every FPU capable of handling float32 and float64 numbers knows what NaN is and handles it the exact same way.

this is one of the many things that sound unintuitive about programming but if you bother to understand the context you realise that if it wasn't this way, it would be way worse. one of the most important skills in our field is to understand computers for what they are, rather than be puzzled that they aren't what you thought they were, and it especially comes out in edge cases like this.

[–] aksdb@lemmy.world 21 points 3 days ago* (last edited 3 days ago) (1 children)

To add to this: the state of being not a number is only relevant to a number. Everything that’s already not a number doesn’t need a specific value to represent this state. It’s actually quite logical.

Apparently one of the few examples of JS not being weird.

[–] Heavybell@lemmy.world 1 points 2 days ago

It is easier to understand the non-weirdness of it in a strongly typed language, IMO. But yes.

[–] alsimoneau@lemmy.ca 2 points 2 days ago (1 children)
[–] arty@feddit.org 11 points 2 days ago (1 children)
$ python 
Python 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> type(float('nan'))
<class 'float'>
[–] alsimoneau@lemmy.ca 1 points 1 day ago (1 children)

That never arises in normal use though. I didn't even know it existed since anything that would yield one raises an exception instead.

[–] arty@feddit.org 1 points 1 day ago

But the OP complains specifically about typeof NaN, and not about Math.sqrt(-1) // NaN

I know this doesn’t count as "normal use", but in Python you get it e.g. via math.inf * 0.

Excellent, now do nulls!