title: Compile time floating point division by zero in C++
body: <p>It is well known, if one divides a floating-point number on zero in run-time then the result will be either infinity or not-a-number (the latter case if the dividend was also zero). But is it allowed to divide by zero in C++ <code>constexpr</code> expressions (in compile time), e.g.</p>
  <pre><code>#include &lt;iostream&gt;
  
  int main() {
      double x = 0.;
      // run-time division: all compilers print &quot;-nan&quot;
      std::cout &lt;&lt; 0./x &lt;&lt; std::endl; 
  
      // compile-time division, diverging results
      constexpr double y = 0.;
      std::cout &lt;&lt; 0./y &lt;&lt; std::endl;
  }
  </code></pre>
  <p>In this program the first printed number is obtained from division in run-time, and all compilers are pretty consistent in printing <code>-nan</code>. (Side question: why not <code>+nan</code>?)</p>
  <p>But in second case the compilers diverge. MSVC simply stops compilation with the error:</p>
  <pre><code>error C2124: divide or mod by zero
  </code></pre>
  <p>GCC still prints <code>-nan</code>, while Clang changes the sign printing “positive” <code>nan</code>, demo: <a href="https://gcc.godbolt.org/z/eP744er8n" rel="nofollow noreferrer">https://gcc.godbolt.org/z/eP744er8n</a></p>
  <p>Does the language standard permit all three behaviors of the compilers for compile-time division: 1) reject the program, 2) produce the same division result as in run-time, 3) produce a different (in sign bit) result?</p>