Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I dug a bit for you, and I think you might be able to use the <code>struct</code> module in combination with the information on at <a href="http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html#kevin_chart" rel="nofollow noreferrer">Kevin's Summary Charts</a>. They explain the exact bit patterns used for the various kinds of IEEE 754 floating point numbers.</p> <p>The only thing you probably will have to be careful for, if I read the topics on this <code>IND</code>-eterminate value, is that that value tends to trigger some kind of floating point interrupt when assigned directly in C code, causing it to be turned into a plain NaN. Which in turn meant those people were advised to do this kind of thing in ASM rather than C since C abstracted that stuff away.. Since it is not my field, and that I am not sure to what extent this kind of value would mess with Python, I figured I'd mention it so you can at least keep an eye for any such weird behaviour. (See the accepted answer for <a href="https://stackoverflow.com/questions/2247447/usefulness-of-signaling-nan">this question</a>).</p> <pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; struct.pack("&gt;d", float('nan')).encode("hex_codec") 'fff8000000000000' &gt;&gt;&gt; import scipy &gt;&gt;&gt; struct.pack("&gt;d", scipy.nan).encode("hex_codec") '7ff8000000000000' </code></pre> <p>Referring to <a href="http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html#kevin_chart" rel="nofollow noreferrer">Kevin's Summary Charts</a>, that shows that <code>float('nan')</code> is actually technically the Indeterminate value, while <code>scipy.nan</code> is a Quiet NaN.</p> <p>Let's try making a Signaling NaN, and then verify it.</p> <pre><code>&gt;&gt;&gt; try_signaling_nan = struct.unpack("&gt;d", "\x7f\xf0\x00\x00\x00\x00\x00\x01")[0] &gt;&gt;&gt; struct.pack("&gt;d", try_signaling_nan).encode("hex_codec") '7ff8000000000001' </code></pre> <p>No, the Signaling NaN gets converted to a Quiet NaN.</p> <p>Now let's try making a Quiet NaN directly, and then verify it.</p> <pre><code>&gt;&gt;&gt; try_quiet_nan = struct.unpack("&gt;d", "\x7f\xf8\x00\x00\x00\x00\x00\x00")[0] &gt;&gt;&gt; struct.pack("&gt;d", try_quiet_nan).encode("hex_codec") '7ff8000000000000' </code></pre> <p>So that's how to make a proper Quiet NaN using <code>struct.unpack()</code>--at least, on a Windows platform.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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