10-01-2015 09:14 AM
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.
Solved! Go to Solution.
10-01-2015 09:19 AM - edited 10-01-2015 09:20 AM
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?)
10-01-2015 09:22 AM
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!
10-01-2015 09:23 AM - edited 10-01-2015 09:29 AM
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> ---'
10-01-2015 09:52 AM - edited 10-01-2015 09:53 AM
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.
10-01-2015 10:43 AM
@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
10-01-2015 10:45 AM - edited 10-01-2015 10:48 AM
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> ---'
10-01-2015 11:07 AM
@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.
10-01-2015 11:18 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
10-01-2015 11:35 AM - edited 10-01-2015 11:41 AM
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> ---'