File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1660,10 +1660,25 @@ std::string GetBoolAssertionFailureMessage(
16601660 return msg.GetString ();
16611661}
16621662
1663- // Helper function for implementing ASSERT_NEAR.
1663+ // Helper function for implementing ASSERT_NEAR. Treats infinity as a specific
1664+ // value, such that comparing infinity to infinity is equal, the distance
1665+ // between -infinity and +infinity is infinity, and infinity <= infinity is
1666+ // true.
16641667AssertionResult DoubleNearPredFormat (const char * expr1, const char * expr2,
16651668 const char * abs_error_expr, double val1,
16661669 double val2, double abs_error) {
1670+ // We want to return success when the two values are infinity and at least
1671+ // one of the following is true:
1672+ // * The values are the same-signed infinity.
1673+ // * The error limit itself is infinity.
1674+ // This is done here so that we don't end up with a NaN when calculating the
1675+ // difference in values.
1676+ if (std::isinf (val1) && std::isinf (val2) &&
1677+ (std::signbit (val1) == std::signbit (val2) ||
1678+ (abs_error > 0.0 && std::isinf (abs_error)))) {
1679+ return AssertionSuccess ();
1680+ }
1681+
16671682 const double diff = fabs (val1 - val2);
16681683 if (diff <= abs_error) return AssertionSuccess ();
16691684
You can’t perform that action at this time.
0 commit comments