File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1660,10 +1660,25 @@ std::string GetBoolAssertionFailureMessage(
1660
1660
return msg.GetString ();
1661
1661
}
1662
1662
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.
1664
1667
AssertionResult DoubleNearPredFormat (const char * expr1, const char * expr2,
1665
1668
const char * abs_error_expr, double val1,
1666
1669
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
+
1667
1682
const double diff = fabs (val1 - val2);
1668
1683
if (diff <= abs_error) return AssertionSuccess ();
1669
1684
You can’t perform that action at this time.
0 commit comments