I would like to compare two doubles with negative values.I have no problem if they are both positive. However, I can't figure out if one of the values is negative. This is I've done.
#include <iostream>
const double PI = 3.14159265358979323846;
bool isEqual(double a, double b, int decimals)
{
double epsilon = pow(10.0, decimals);
if( fabs( a - b) < epsilon)
return true;
return false;
}
int main()
{
double Theta;
Theta = 3.1415;
if ( isEqual(Theta, -PI, 10) )
{
std::cout << "Theta == -PI " << Theta << " == " << -PI << std::endl;
}
Theta = -3.1415;
if ( isEqual(Theta, -PI, 10) )
{
std::cout << "Theta == -PI " << Theta << " == " << -PI << std::endl;
}
std::cin.get();
return 0;
}