Skip to main content
12-Amethyst
August 8, 2023
Question

Usage of NaN in calculations

  • August 8, 2023
  • 3 replies
  • 3068 views

Every function, which is called with an argument of NaN should deliver NaN as a result !

Some functions deliver odd values such as log, ln, or ln0. Very problematic are the functions min and max which deliver min(NaN)=0 and max(NaN)=0. This can lead to incorrect results, as it was the case in our calculations. This error occured with Prime 8.

Prime8_minmaxNaN.gif

 

 

3 replies

ttokoro
21-Topaz I
August 8, 2023

Prime 9 also.

image.pngimage.png

So, we should do.

image.pngimage.pngimage.pngimage.png

But, if image.pngthen alsoimage.png

t.t.
25-Diamond I
August 9, 2023

@ttokoro wrote:

 

So, we should do.

image.pngimage.pngimage.png

 


This does not help much as it still fails if NaN is the first entry of the vector!

Werner_E_0-1691572521372.png

 

 

23-Emerald IV
August 8, 2023

Sorry to say, but this is behaviour as designed; according to the Help information on NaN in "About the NaN (Not a Number) Built-In Constant":

"... A NaN can only be processed by functions specifically written to use it. Other functions may return errors or incorrect results if passed a NaN."

After all, it's PTC sofware.

 

Mathcad 11 gives:

LucMeekes_0-1691527236336.png

Success!
Luc

Manfred_F12-AmethystAuthor
12-Amethyst
August 9, 2023

Hi Luc,

did you try this on Prime8:

Prime8_logNaN.gif

Manfred

25-Diamond I
August 9, 2023

The bug (or unexpected and undesired result, as its behavior according to the help) with "min" and "max" is already present in Mathcad, so we can blame PTC only for not fixing it.

Werner_E_1-1691572974962.png

What we can blame PTC for is for making it even worse as your example with the logs showed

Werner_E_2-1691573066793.png

I am surprised that the imaginary part is pi. Would expect at least an integer multiple of 2 pi !?

Here is the same in MC15

Werner_E_3-1691573100074.png

Here is something "nice", too

Werner_E_4-1691573625027.png

Note that NaNi and also the number in the exponent are labeled as "Unit" ????

In MC15 this still was OK

Werner_E_5-1691573703956.png

 

Even though the help states that using functions on NaN may give wrong results, you may consider opening a ticket at PTC support and report this bug and/or demand that this undesirable behavior should be changed.

 

 

ttokoro
21-Topaz I
August 9, 2023

Using vector M, Edit: Without NaN fix.

image.pngimage.pngimage.png

image.pngimage.pngimage.png

t.t.
25-Diamond I
August 9, 2023

Which results do you get when you use a vector without any NaN's? 😉

 

EDIT: AH, I see that you have editted your post and fixed your functions to deal correctly with that case 😄 

Manfred_F12-AmethystAuthor
12-Amethyst
August 9, 2023

I would expect that min() or max() filters out the NaN and calculates then min/max from the rest. If there is no value left (all values are NaN) then the result should be NaN. I tried several combinations and it seems to depend on the sign and position of NaNs:

Prime8_minmaxNaN2.gif