When I compile the following code with g++ (4.8.1 or 4.9.0) or clang++ (3.4) I get different outputs.
#include
#include
int mai
The standard says in [complex.numbers]
(26.4/3):
If the result of a function is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.
There are no specifics on how division should be implemented for complex numbers. Only in [complex.member.ops]
it says:
complex
& operator/=(const complex & rhs); Effects: Divides the complex value
rhs
into the complex value*this
and stores the quotient in*this
. Returns:*this
.
and in [complex.ops]
:
template
complex operator/(const T& lhs, const complex & rhs); Returns:
complex
.(lhs) /= rhs
As the inverse of 1.e-162
is 1.e+162
and this number is in the range of representable values for a double
, the behavior is well defined.
Thus gcc gets it right and clang has a bug.