comparison - Comparing two doubles in c++ not yielding correct result -


i have 2 doubles, , b, in c++ should equal reason not being treated such. following code:

cout << << "==" << b << ": " << (a == b) << endl; 

is outputting

0.5 == 0.5: 0 

any ideas why resolving false?

to avoid errors when comparing decimals might useful use function:

bool aresame(double a, double b) {     return fabs(a - b) < epsilon; } 

where epsilon represented small number such .001

grabbed this question.

edit: including <limits> 1 use std::numeric_limits<double>::epsilon()


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -