title: Maximum number of decimal digits that can affect a double
body: <p>Consider decimal representations of the form d1.d2d3d4d5...dnExxx where xxx is an arbitrary exponent and both d1 and dn are nonzero.</p>
  
  <p>Is the maximum n known such that there exists a decimal representation d1.d2d3d4d5...dnExxx such that the interval (d1.d2d3d4d5...dnExxx, d1.d2d3d4d5...((dn)+1)Exxx) contains an IEEE 754 double?</p>
  
  <p>n should be at least 17. The question is how much above 17.</p>
  
  <p>This number n has something to do with the number of digits that it is enough to consider in a decimal-to-double conversion such as <code>strtod()</code>. I looked at the source code for <a href="http://www.netlib.org/fp/dtoa.c">David M. Gay's implementation</a> hoping to find an answer there. There is an allusion to “40” but it is unclear whether this is a consequence of a sound mathematical result or just a statistically safe bound. Also the comment about “truncating” makes it sound like 0.5000000000000000000000000000000000000000000000000001 may be converted to 0.5 in round-upwards mode.</p>
  
  <p><a href="https://github.com/BlankOn/musl/blob/master/src/internal/floatscan.c">Musl's implementation</a> seems to read approximately 125*9 digits, which is a lot. Then it switches to “sticky” mode:</p>
  
  <pre><code>if (c!='0') x[KMAX-4] |= 1;
  </code></pre>
  
  <p>Finally, how does the answer change when substituting “contains an IEEE 754 double” with “contains the midpoint of two consecutive IEEE 754 doubles”?</p>