This has already been answered, but I will add two cents. You may find it helpful to make the doubling comparison function if you plan to do this often. The idea is to verify that fabs(ab) < epsilon where epsilon is a small value representing the number of errors that can be tolerated.
bool is_equal( double a, double b, const double epsilon = 1e-5 ) { double c = a - b; return c < epsilon && -c < epsilon;
Then this is just a case of this:
assert( is_equal(getAvgDensity('A'), 5.395) );
source share