IEEE 754 NaN Behavior

Discussions center on the properties and quirks of NaN in IEEE 754 floating-point arithmetic, such as NaN != NaN, comparisons with infinities, signed zeros, and standard compliance across languages.

📉 Falling 0.5x Programming Languages
2,487
Comments
19
Years Active
5
Top Authors
#5470
Topic ID

Activity Over Time

2008
3
2009
4
2010
35
2011
62
2012
73
2013
45
2014
136
2015
106
2016
77
2017
153
2018
238
2019
90
2020
211
2021
298
2022
239
2023
275
2024
208
2025
231
2026
3

Keywords

NCEG IEC NAN PHP devsanon.com dlang.org NULL riscv.org SQL ISA nan floating point floating infinity ieee php zero 127 mathematical interrupt

Sample Comments

lmm Feb 19, 2018 View on HN

If your language can't use signalling NaNs correctly, get a better language.

magicalhippo Jul 29, 2019 View on HN

This is default IEEE 754 behavior.https://en.wikipedia.org/wiki/NaN

bushin May 23, 2017 View on HN

NaN stuff works according to the IEEE 754 spec.

chrisseaton Mar 5, 2021 View on HN

You can look these things up for yourself - they're standardised in most language's implementations in something called IEEE 754. In the cases you've asked about they're false and true. Is this what you want in all cases? No. Is this what you want in some cases? Yes. It's a tradeoff. You can still observe the difference by dividing by zero (which should be another indication that these aren't real numbers as we're conventionally understand them.)

xyclos Jul 31, 2017 View on HN

NaN is meant to represent a non-sensical mathematical operation (like divide by 0). One non-sensical mathematical operation is not the same as some other non-sensical mathematical operation (1/0 !== Infinity/Infinity)

lifthrasiir Jan 16, 2024 View on HN

Pretty sure that their behaviors on NaN arguments will also differ.

PDoyle Dec 14, 2016 View on HN

They'd differ for floating-point NaNs.

mjmas Oct 31, 2025 View on HN

But NaN is also a quirk of IEEE754 floating pount math.

efaref Feb 17, 2017 View on HN

Not sure I like the sound of that. It sounds like the floating point wat of "NaN != NaN".

goatlover Jan 12, 2020 View on HN

Or there's NaN which just results in NaN and doesn't equal itself. No need to crash.