Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>CPython definition of nan</strong></p> <p>When Python reports a <code>nan</code>, where does that come from?</p> <ul> <li>Result of a calculation (platform specific values?)</li> <li><code>Py_NAN</code> in the CPython C source code <ul> <li>defined as <code>(Py_HUGE_VAL * 0.)</code> <ul> <li>Value is platform-specific</li> <li><code>Py_HUGE_VAL</code> is probably defined as <code>HUGE_VAL</code>--it has a note to say it should be <code>HUGE_VAL</code> except on platforms where that is broken.</li> </ul></li> </ul></li> <li><code>float('nan')</code> which is defined from <code>Py_NAN</code> in CPython's C source code.</li> </ul> <p><strong>Reading Python and pywin32 Source Code</strong></p> <p>I've had a look at the C source code for <code>pywin32</code>, in particular <code>win32com</code>, which forms the Python↔COM translation layer. That code:</p> <ul> <li>takes the input object</li> <li>calls <code>PyNumber_Float()</code> to convert it to a Python <code>float</code> (if it isn't already)</li> <li>calls <code>PyFloat_AsDouble()</code> to convert it to a plain C <code>double</code> value. <ul> <li>This simply returns the C <code>double</code> directly contained in the <code>PyFloatObject</code> member <code>ob_fval</code>.</li> </ul></li> </ul> <p>So it looks as though I've traced a <code>NaN</code> from the COM interface back to a plain C <code>double</code> type containing <code>Py_NAN</code>, whatever that turns out to be on the Windows platform.</p> <p><strong>TestStand NAN Value</strong></p> <p>Now I've tried this with NI TestStand. First I tried:</p> <pre><code>quiet_nan = struct.unpack("&gt;d", "\x7f\xf8\x00\x00\x00\x00\x00\x01")[0] # Set the variable's value in TestStand locals_prop_object.SetValNumber(var_name, 0, quiet_nan) </code></pre> <p>But that still appeared in TestStand as <code>IND</code>. So then I created a TestStand file with variables set to <code>IND</code> and <code>NAN</code>, and read the values from Python. It turns out that TestStand's <code>NAN</code> has a value of <code>FFFF000000000001</code>. According to <a href="http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html#kevin_chart" rel="nofollow">Kevin's Summary Charts</a> that is a <em>negative</em> quiet NAN. TestStand's <code>IND</code> does have the expected value for <em>Indeterminate</em>, <code>FFF8000000000000</code>.</p> <p><strong>Success</strong></p> <p>So, after all that, I have succeeded in setting a NAN in TestStand, from Python:</p> <pre><code># Make a NAN suitable for TestStand teststand_nan = struct.unpack("&gt;d", "\xff\xff\x00\x00\x00\x00\x00\x01")[0] # Set the variable's value in TestStand locals_prop_object.SetValNumber(var_name, 0, teststand_nan) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload