LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing NaN constant(s) with buggy results!!

Solved!
Go to solution

Hey NI Forum people!

 

I know I should be very carefull when making comparisons on floating point numbers due to rounding and representation issues.

 

That said, I got completely caught off guard when I wanted a 'true' boolean if a number was NOT equal to 'NaN'.. I wasn't thinking about it too much, just slinging wires for a quick conditional for loop terminal for some testing I was doing in a temporary VI, and implemented this with a 'not equal to' primitive (instead of the 'Not a Number/path/refnum' primitive.

 

The result caught me by surprise, and when I dug into it, it became even weirder... turns out comparing a single constant to itself will yield unexpected results too!! 

Is this how it has always been or is this NEW in LV 2015?? 

 

I included an LV 2011 version if anyone wants to try on an older version.. I ran this on a Windows 7 PC.

 

snippet.pngfront panel.png

QFang
-------------
CLD LabVIEW 7.1 to 2016
Message 1 of 13
(6,291 Views)
Solution
Accepted by topic author QFang

Whilst it might not make sense, it is documented behaviour though.

 

Documentation:


Equal? Function
If you compare two inputs with the value not a number, NaN, or one input with the value NaN to an input with another value, this function always returns FALSE. Use the Not a Number/Path/Refnum? function to compare one or more inputs with a value of NaN.

 (same applies to Not Equal?)


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 13
(6,285 Views)

Damn, you know, checking the documentation for THAT primitive just honestly didn't cross my mind... I "knew" very well what it was doing.. or so I thought!

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 3 of 13
(6,278 Views)

There's a forum topic on here somewhere about caveats to LabVIEW that some people could get tripped up by, but I can't seem to find it... I think Jack Dunaway started it.

Anyways, this was posted in there a while ago.

 

Here's an NI page about it at least.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 4 of 13
(6,274 Views)

Isn't this part of the IEEE 754 floating point standard? There is a binary representation for NaN, and then the second part of the definition is that Value != Value if and only if Value == NaN. With C-code I often use Value != Value to check for NaN.

0 Kudos
Message 5 of 13
(6,237 Views)

@shansen1 wrote:

Isn't this part of the IEEE 754 floating point standard


Yes. Since the original source is frustratingly behind a paywall, here's a link that discusses this issue: https://en.wikipedia.org/wiki/IEEE_floating_point

 


@James.M wrote:

There's a forum topic on here somewhere about caveats to LabVIEW that some people could get tripped up by


 http://forums.ni.com/t5/BreakPoint/LabVIEW-Minutiae-that-may-bite-you-someday/m-p/1122234/highlight/...

Message 6 of 13
(6,206 Views)

There it is! Thanks.

 

(I swear, you must have a script that pings you every time your name is mentioned...)

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 13
(6,202 Views)

@James.M wrote:

 

(I swear, you must have a script that pings you every time your name is mentioned...)


The forums allow you to configure a search subscription, which should do this if your name is unique enough. Haven't tried it myself. Maybe I'll try it now, but I expect I will mainly get noise from threads I participate in.


___________________
Try to take over the world!
Message 8 of 13
(6,180 Views)

And the fact that some of us would need to subscribe to many mis-spellings of our name, Hooovahh, hoovah, hooovah, hoovahh, then there are our actual names.  Sounds like a lot of work, just read every post on the forums instead. 

Message 9 of 13
(6,171 Views)

Hey, that's neat! Looks like the following query works for me. It even shows a post from Bob Schor that I missed where he called me out a while ago.

james.morris OR jamesmorris OR "james morris" -"James.Morris wrote"

 

 

I expect "tst" will show up everywhere. And yeah, Hooovahhhhhh is easy to get wrong when summoning you...

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 10 of 13
(6,160 Views)