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

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

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

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