That is called floating point approximation (or imprecision):
If you include the header cfloat
there are some definitions. In particular, DBL_EPSILON
, which is the smallest number that 1.0 + DBL_EPSILON != 1.0
, which is usually 1e-9
(and -2.068231e-013
is much smaller than that. If you do the following piece of code, you can check if it is zero or not:
// The complete formula is std::abs(a - b), but since b is zero, I am ommiting it
if (std::abs(number.imag()) < DBL_EPSILON) {
// The number is either zero or very close to zero
}
For example, you can see the working code here: http://ideone.com/2OzNZm