//code
int testFunc(double value)
double test = 0.0;
if(val<=test)
std::cout<<"Both are Equal"<<std::endl;
///
The if loop may result to true if value ==0 but comparison of floating point values are not proper and violate the coding standard.
How can I carry out such a comparison??????????
Regards,
Sanjib
comparison of floating point numbersfloating poing comparison
Page 1 of 1
3 Replies - 1359 Views - Last Post: 08 October 2010 - 10:56 AM
Replies To: comparison of floating point numbers
#3
Re: comparison of floating point numbers
Posted 08 October 2010 - 09:41 AM
Decide how much of an error (rounding error) you are willing to accept -- let's call it epsilon -- and then you can do something like this:
int testFunc(double value) {
double test = 0.0, epsilon = 0.00001;
if(value < test + epsilon && value > test - epsilon)
std::cout<<"Both are Equal"<<std::endl;
}
#4
Re: comparison of floating point numbers
Posted 08 October 2010 - 10:56 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote









|