How to simulate NaN (not a number) - values for testing purposes

 

In some cases, it is necessary to simulate NaN (not a number) values for testing purposes (f.e. if you want to test, how your business logic is able to handle such values (they could come from PLCs in case of errors).

Here is a code-sample for generating a NaN-value (-1.#QNAN0) with a Control-Script:

main()<o:p></o:p>

{<o:p></o:p>

blob source;<o:p></o:p>

int len, pos;<o:p></o:p>

string s;<o:p></o:p>

float value;<o:p></o:p>

<o:p> </o:p>

s = "7F,FF,FF,FF";<o:p></o:p>

<o:p> </o:p>

source = s;<o:p></o:p>

<o:p> </o:p>

len = 4;<o:p></o:p>

pos = 0;<o:p></o:p>

<o:p> </o:p>

blobGetValue(source, pos, value, len, FALSE);<o:p></o:p>

<o:p> </o:p>

DebugN(isnan(value));<o:p></o:p>

//this will result into a TRUE output<o:p></o:p>

<o:p> </o:p>

dpSet("System1:TestValue.", value);<o:p></o:p>

//Is some other Script is connected to this DPE, it must be able to handle this value<o:p></o:p>

<o:p> </o:p>

}<o:p></o:p>

Date added:
Last revised:
Hits:
4.927
Version:
ALL Versions
Rating:
Rating: 0.0. 0 vote(s). No rating done at all.
Your vote was '' (0 of 5) You are an anonymous user.
You may log on to do personalized votings
Click the rating bar to rate this item Please log on to do ratings
  • Notification

    FE user cannot be identified! (1403201096)

  • Information

    Not already rated (1403203414)

Tags:
Engineering, Special Functions / Features