sinemakinci1 / Cpp-Copilot-VSC-Demo

0 stars 0 forks source link

Floating point division by zero #5

Open TartanLlama opened 9 months ago

TartanLlama commented 9 months ago

https://github.com/sinemakinci1/Cpp-Copilot-VSC-Demo/blob/21a2875a135da17b8ab0990026c4b331c9091dfc/src/Calculator.h#L31

Teeeeeeechnically floating point division by zero is well-defined if the implementation uses IEEE 754 floats. Not sure if it's worth mentioning or not, but you might get some language lawyer going "well, actually"

The result of built-in division is lhs divided by rhs. If rhs is zero, the behavior is undefined. If both operands have an integral type, the result is the algebraic quotient (performs integer division): the quotient is truncated towards zero (fractional part is discarded). If both operands have a floating-point type, and the type supports IEEE floating-point arithmetic (see std::numeric_limits::is_iec559):

  • If one operand is NaN, the result is NaN.
  • Dividing a non-zero number by ±0.0 gives the correctly-signed infinity and FE_DIVBYZERO is raised.
  • Dividing 0.0 by 0.0 gives NaN and FE_INVALID is raised.