title: std::fmod abysmal double precision
body: <p><code>fmod(1001.0, 0.0001)</code> is giving <code>0.00009999999995</code>, which seems like a very low precision (10<sup>-5</sup>), given the expected result of <code>0</code>.</p>
  <p>According to <a href="https://en.cppreference.com/w/cpp/numeric/math/fmod" rel="noreferrer">cppreference</a>, <code>fmod()</code> is implementable using <code>remainder()</code>, but <code>remainder(1001.0, 0.0001)</code> gives <code>-4.796965775988316e-14</code> (still far from <code>double</code> precision, but much better than 10<sup>-5</sup>).</p>
  <p>Why does <code>fmod</code> precision depend on input arguments that much? Is it normal?</p>
  <p>MCVE:</p>
  <pre><code>#include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main() {
      double a = 1001.0, b = 0.0001;
      cout &lt;&lt; setprecision(16);
      cout &lt;&lt; &quot;fmod:      &quot; &lt;&lt; fmod(a, b) &lt;&lt; endl;
      cout &lt;&lt; &quot;remainder: &quot; &lt;&lt; remainder(a, b) &lt;&lt; endl;
      cout &lt;&lt; &quot;actual:    &quot; &lt;&lt; a-floor(a/b)*b &lt;&lt; endl;
      cout &lt;&lt; &quot;a/b:       &quot; &lt;&lt; a / b &lt;&lt; endl;
  }
  </code></pre>
  <p>Output:</p>
  <pre class="lang-none prettyprint-override"><code>fmod:      9.999999995203035e-05
  remainder: -4.796965775988316e-14
  actual:    0
  a/b:       10010000
  </code></pre>
  <p>(same result with GCC, Clang, MSVC, with and without optimization)</p>
  <p><a href="https://gcc.godbolt.org/z/58MjKf" rel="noreferrer">Live demo</a></p>