Re: C2124 is most disrespectful of IEEE floating point arithmetic

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Dr Pizza wrote:
Sean M. DonCarlos wrote:

"John Carson" wrote:

The point is that

bool result = numeric_limits<float>::is_iec559;

sets result to true in VC++. This rather implies that VC++ floats
do have to adhere to IEC 559.
They do. The compiler doesn't:
If the compiler doesn't then the compiler should leave well enough
alone. If the compiler is too stupid to compute the value at compile
time then it should leave it to be evaluated at runtime (when it works).

There is no proscription against writing 1.0f / 0.0f in C++. The
compiler should not reject such an expression (provided that the
expression occurs in an appropriate place, of course).

Conforming compilers are required to reject the expression regardless of iec 559 support:

5/5
"If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined, unless such an expression is a constant expression (5.19), in which case the program is ill-formed."

That seems pretty clear to me. 1.0/0.0 is a constant expression, and hence a compiler error is expected. If that's not sufficient for you, then there's also this:

5.6/4
"The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined;"

Tom
.



Relevant Pages