Using GCC 4.8. * when the warning is -Wfloat-equal
activated, the compiler warns of strict comparisons between the flotation number, as in the following example:
double x = 3.14159;
double y = 1.11111;
if(x == y)
{ }
Now imagine that I need a class that contains double variables and defines an equality operator:
class Complex // (it only an example)
{
private:
double re;
double im;
public:
bool operator == (Complex const& z) const;
};
bool Complex::operator == (Complex const& z) const
{
return (this->re == z.re) && (this->im == z.im);
}
This does exactly what I expect. Of course, it raises a warning when compiling the class. To avoid this (because I understand the warning, thanks to the compiler, but I want to do this, and I don't want to continue to see the warning), I tell the compiler as follows:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
bool Complex::operator == (Complex const& z) const
{
return (this->re == z.re) && (this->im == z.im);
}
#pragma GCC diagnostic pop
, Complex.cpp
. - ==
, exaccty, ==
( -Wfloat-equal
). , :
GCC ( -Wfloat-equal
), ==
? , , .
. , bool equals(...) const
, bool operator == (Complex const&,Complex const&)
, .
. ++ 11 .