09-27-2024 05:09 PM
I have a cluster of data, and I wanted to see if it had changed. I keep a master copy and an active copy, and planned to use a check for change in data to activate/deactivate a Save button.
Problem is, if any values in the cluster are NaN, the "is equal" comparison will always be false, since NaN is never equal to NaN.
This took some head scratching to figure out, but in the meantime, I discovered that if you compare elements in a cluster, in stead of aggregates, you get an output that is a cluster of (clusters of arrays of...) booleans, showing exactly which elements are different.
In my case, pre-conditioning the cluster values (converting NaNs to zeros) prior to comparison will fix the issue.
Solved! Go to Solution.
09-27-2024 05:23 PM
You could use the NaN/Path/Refnum? comparison to see if you have any NaNs or to check unequal values in the array.
Replacing NaNs with zeros before comparison may be easier than multiple comparisons.
09-28-2024 01:21 AM
What kind of cluster is it? Mixed? All numeric? all scalar DBLs, etc?
You get a "not equal=true" if the NaN remains a NaN, or if a NaN changed to a valid number, or a valid number change to NaN. Only in the first case the cluster does not change.
Preconditioning by replacing all NaNs with zero is only a good idea if zero is a good sentinel value that can never occur as valid number. You could e.g. pick Inf instead.
09-28-2024 08:05 AM - edited 09-28-2024 08:23 AM
Has a cluster element changed from NaN to a valid number (or vice-versa)?
This gets convoluted! Take the input clusters, run each through both = and ≠, (compare elements) to themselves (That is, compare each cluster to itself). Then Negate the XOR of each = and ≠.. This gives you TRUE elements where a NaN exists in each input cluster. XOR those and get a TRUE where only 1 NaN occurs in any element. Now we rigorously have solved for the "has NaN Changed?" Question.
OR "has NaN Changed?" with the two inputs compared for inequally. Now you have a cluster of "Value Changed?"
Cluster to Array, OR Array elements to get Value Changed? (Aggregate.) Negate for Equals?
09-28-2024 11:05 PM
The issue is that this is large complex cluster with nested clusters containing arrays, and NaNs are used as placeholders for some of the data, especially optional values that the use rmight update.
Pre-parsing it is just not worth the trouble (for now), so I'm going to forge informing the user that the data has changed.
It does make we wish there were a more general tool for this type of comparison, that accepted, at least optionally that NaN = NaN.
09-28-2024 11:22 PM - edited 09-28-2024 11:36 PM
@littlesphaeroid wrote:
It does make we wish there were a more general tool for this type of comparison, that accepted, at least optionally that NaN = NaN.
That you have to argue with IEEE. The IEEE-754 Standard defines how floating point values work and NaN MUST fail every comparison. So NaN = AnyValue is false ... even when AnyValue is Not a Number. That's just the way it works! NaN just isn't anywhere on the numberline and cannot be evaluated as any real number since- it isn't a number!
We don't know what NaN is but, we are sure that it is something other than a number.
09-28-2024 11:32 PM - edited 09-29-2024 01:33 AM
@JÞB wrote:
The IEEE-754 Standard defines how floating point values work an NaN MUST fail every comparison.
More precisely, it must fail every "equal" comparison. 🙂
EDIT:... fail every comparison except "not equal"
09-28-2024 11:45 PM
@altenbach wrote:
@JÞB wrote:
The IEEE-754 Standard defines how floating point values work an NaN MUST fail every comparison.More precisely, it must fail every "equal" comparison. 🙂
It fails <, <=, =, => and > (I may have unintentionally suggested earlier that NaN ≠ NaN is false. Oops, NaN ≠ NaN is TRUE. of course that simplifies the convoluted logic in my earlier post)
THUS my once yearly post with bug quota is satisfied.
09-29-2024 09:35 AM
Hi
NaN is a unique combination of 0 and 1's and you can compare it.
Like this :
Regards
09-29-2024 10:08 AM - edited 09-29-2024 10:17 AM
@softball wrote:NaN is a unique combination of 0 and 1's and you can compare it.
No, it is not unique. Many bit patterns translate to NaN:
NaNs are encoded with the exponent field filled with ones (like infinity values), and some non-zero number in the significand field (to make them distinct from infinity values); this allows the definition of multiple distinct NaN values, depending on which bits are set in the significand field, but also on the value of the leading sign bit (but applications are not required to provide distinct semantics for those distinct NaN values).
With some effort, we can create many different NaN values.
As an illustration, have a look here: