From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

max & min function

The max & min function behaves differently in LabVIEW 6.1 compared to 6.0.2. When comparing between NaN and 0.0, the function returned NaN as the max,in 6.0.2. In 6.1, it retunrs 0.0 as the max. Why is this so?
0 Kudos
Message 1 of 3
(2,531 Views)
You should not rely on assumed behavior of functions when treating NaN. You should treat the case explicitly on your diagram.

By IEEE standard the comparisons
X > NaN should return FALSE
X < NaN should also return FALSE.

Then the output of a MinMax function with a NaN input actually depends on how you compare both inputs.

using for example
if (X > Y) then
Max = X;
Min = Y;
else
Max = Y;
Min = X;
end

This implementation always returns Max = Y and Min = X when comparing with a NaN input because (X > Y) is FALSE.

On the other hand, the implementation

if (X < Y) then
Max = Y;
Min = X;
else
Max = X;
Min = Y;
end

does return swapped values for Min and Max for NaN inputs.

Usually, primitives don't check
explicitely for NaN values because it would unecessarly bloat the code. This kind of NaN check is left to the programmer because anyway the output of MinMax function is meaningless when inputs are NaN.


LabVIEW, C'est LabVIEW

Message 2 of 3
(2,531 Views)
Thanks for the reply. It is interesting that both the max AND the min returned are zero!
0 Kudos
Message 3 of 3
(2,531 Views)