274
you are viewing a single comment's thread
view the rest of the comments
[-] b3nsn0w@lemmy.world 19 points 4 hours ago

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 9 points 3 hours ago* (last edited 3 hours ago)

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.

this post was submitted on 14 Nov 2026
274 points (97.9% liked)

Programmer Humor

34135 readers
1937 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