title: scanf(), field width, inf and nan
body: <p>Per the C standard from 1999, <code>scanf()</code> and <code>strtod()</code> should accept infinity and NaN as inputs (if supported by the implementation).</p>
  
  <p>The descriptions of both functions have peculiar language, which may be open to interpretations.</p>
  
  <p><code>scanf()</code>:</p>
  
  <blockquote>
    <p>An input item is defined as the longest sequence of input characters
    which does not exceed any specified field width and which is, or is a
    prefix of, a matching input sequence.</p>
  </blockquote>
  
  <p><code>strtod()</code>:</p>
  
  <blockquote>
    <p>The subject sequence is defined as the longest initial subsequence of
    the input string, starting with the first non-white-space character,
    that is of the expected form.</p>
  </blockquote>
  
  <p>While the latter excerpt appears to be strict in requiring the specific forms of "INF", "INFINITY", "NAN" or "NAN(n-char-sequence-opt)", the former isn't and one would think that the following code should produce infinity and NaN because the field width covers prefixes of matching input sequences:</p>
  
  <pre><code>int r;
  double d;
  d = 0; r = sscanf("inf", "%2le", &amp;d);
  printf("%d %e\n", r, d);
  d = 0; r = sscanf("nan", "%2le", &amp;d);
  printf("%d %e\n", r, d);
  </code></pre>
  
  <p>There's also this bit on <code>scanf()</code>:</p>
  
  <blockquote>
    <p>a,e,f,g Matches an optionally signed floating-point number, infinity,
    or NaN, whose format is the same as expected for the subject sequence
    of the strtod function. The corresponding argument shall be a pointer
    to floating.</p>
  </blockquote>
  
  <p>Is this simply a failure to document that a field width of 2, which is shorter than the expected shortest forms ("inf" or "nan"), does not make the otherwise matching prefixes "in" and "na" valid matches?</p>