| 1059 | // Helper template for implementing FloatLE() and DoubleLE(). |
| 1060 | template <typename RawType> |
| 1061 | AssertionResult FloatingPointLE(const char* expr1, |
| 1062 | const char* expr2, |
| 1063 | RawType val1, |
| 1064 | RawType val2) { |
| 1065 | // Returns success if val1 is less than val2, |
| 1066 | if (val1 < val2) { |
| 1067 | return AssertionSuccess(); |
| 1068 | } |
| 1069 | |
| 1070 | // or if val1 is almost equal to val2. |
| 1071 | const FloatingPoint<RawType> lhs(val1), rhs(val2); |
| 1072 | if (lhs.AlmostEquals(rhs)) { |
| 1073 | return AssertionSuccess(); |
| 1074 | } |
| 1075 | |
| 1076 | // Note that the above two checks will both fail if either val1 or |
| 1077 | // val2 is NaN, as the IEEE floating-point standard requires that |
| 1078 | // any predicate involving a NaN must return false. |
| 1079 | |
| 1080 | ::std::stringstream val1_ss; |
| 1081 | val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) |
| 1082 | << val1; |
| 1083 | |
| 1084 | ::std::stringstream val2_ss; |
| 1085 | val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) |
| 1086 | << val2; |
| 1087 | |
| 1088 | return AssertionFailure() |
| 1089 | << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n" |
| 1090 | << " Actual: " << StringStreamToString(&val1_ss) << " vs " |
| 1091 | << StringStreamToString(&val2_ss); |
| 1092 | } |
| 1093 | |
| 1094 | } // namespace internal |
| 1095 |
nothing calls this directly
no test coverage detected