Demystifying NaN for the Working Programmer
lucidchart.com
Demystifying NaN for the Working Programmer
1–10 of 38 posts
Re: Demystifying NaN for the Working Programmer
#2Re: Demystifying NaN for the Working Programmer
#3In the meeting when they went over the code the guy who did it said we were wondering why you did this? So I had to explain NaN to him. He really did not know it existed. At any rate I thought this is a weird thing not to know anything at all about.
Re: Demystifying NaN for the Working Programmer
#4Re: Demystifying NaN for the Working Programmer
#5Re: Demystifying NaN for the Working Programmer
#6I love NaNs, especially their "infectious" quality. Initializing float variable to NaNs before first assignment can make a lot of errors immediately obvious. I wish there were a NaN for integers.
Re: Demystifying NaN for the Working Programmer
#7Well, you test for it by comparing the value against itself and seeing if that returns false.
(There’s also a bit of confusion on by value vs. by reference comparison and the actual bit value on a NaN, which isn’t quite right.)
Re: Demystifying NaN for the Working Programmer
#8> The only reliable way to test for NaN is to use a language-dependent built-in function; the expression a === NaN is always false Well, you test for it by comparing the value against itself and seeing if that returns false. (There’s also a bit of confusion on by value vs. by reference comparison and the actual bit value on a NaN, which isn’t quite right.)
Re: Demystifying NaN for the Working Programmer
#9> The only reliable way to test for NaN is to use a language-dependent built-in function; the expression a === NaN is always false Well, you test for it by comparing the value against itself and seeing if that returns false. (There’s also a bit of confusion on by value vs. by reference comparison and the actual bit value on a NaN, which isn’t quite right.)
Signaling NaNs raise exceptions in some operations. Is comparison one of these?
Re: Demystifying NaN for the Working Programmer
#10Imagine doing if(x) ..., where x can be NaN. Shouldn't that throw an exception in most cases? Why are our compilers not doing it that way?
On the other hand, I would strongly discourage 'if(x)' where x is a float that may be NaN purely because the 'correct' behaviour here isn't clear to me.