The C++ standard says:
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.
and
The binary / operator yields the quotient from the division of the first expression by the second. If the quotient a/b is representable in the type of the result [snip]; otherwise, the behavior of a/b is undefined.
If I have:
double x = 1.0 / 3.0;
The result of the division of 1 by 3 is the real number "one third". One third is not representable in the type of the result (double
, usually the IEEE754 double-precision binary64 floating point type).
Does that mean that the above statement is an undefined operation? Surely it cannot be - but I don't understand how it isn't?