c++ - Checking if two vectors are equal -


i have 2 vectors:

std::vector<double> calculatedvalues = calculatevalues(); std::vector<double> expectedvalues = {1.1, 1.2}; 

i using cpputest verify if these vectors equal:

check_true(calculatedvalues == expectedvalues) 

this working. however, wondering whether shouldn't use tolerance, because after comparing doubles.

to compare floating point values should this:

bool is_equal(double a, double b) {      return (abs(a-b)/b < 0.0001); // 0.00001 value can relative value } 

you can adapt compare vectors.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -