I'm having some trouble testing floating point values for equality with Google Test 1.7.0.
My assertion looks like this:
ASSERT_NEAR(124691356.375f, actual, DELTA);
The test fails with the following error:
The difference between 124691356.375f and actual is 3.625, which exceeds DELTA, where 124691356.375f evaluates to 124691360, actual evaluates to 124691356.375, and DELTA evaluates to 0.0625.
What's going on? actual
and the expected result are clearly within the allowable error of 0.0625. Why is gtest evaluating the floating point literal 124691356.375f
this way?
Update: DELTA
and actual
are of type double, and the expected value is a float literal. If I change the literal to be a double, or change the other arguments to be floats (so that everything is of the same type) the test passes. The question still stands - what is causing this behavior when the types don't match?