title: Propagation of NaN through calculations
body: <p>Normally, NaN (not a number) propagates through calculations, so I don't need to check for NaN in each step. This works almost always, but apparently there are exceptions. For example:</p>
  
  <pre><code>&gt;&gt;&gt; nan = float('nan')
  &gt;&gt;&gt; pow(nan, 0)
  1.0
  </code></pre>
  
  <p>I found the <a href="http://en.wikipedia.org/wiki/NaN#Function_definition" rel="nofollow">following comment</a> on this:</p>
  
  <blockquote>
    <p>The propagation of quiet NaNs through arithmetic operations allows
    errors to be detected at the end of a sequence of operations without
    extensive testing during intermediate stages. However, note that
    depending on the language and the function, NaNs can silently be
    removed in expressions that would give a constant result for all other
    floating-point values e.g. NaN^0, which may be defined as 1, so in
    general a later test for a set INVALID flag is needed to detect all
    cases where NaNs are introduced.</p>
    
    <p>To satisfy those wishing a more strict interpretation of how the power
    function should act, the 2008 standard defines two additional power
    functions; pown(x, n) where the exponent must be an integer, and
    powr(x, y) which returns a NaN whenever a parameter is a NaN or the
    exponentiation would give an indeterminate form.</p>
  </blockquote>
  
  <p>Is there a way to check the INVALID flag mentioned above through Python? Alternatively, is there any other approach to catch cases where NaN does not propagate?</p>
  
  <p>Motivation: I decided to use NaN for missing data. In my application, missing inputs should result in missing result. It works great, with the exception I described. </p>