Given IEEE-754 format for floats and doubles, we can assume that float -> double promotion is lossless. Given this, we can assume that if we do the standard relative comparison of |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get the same result if we do this for floats, as if we do this for doubles that were promoted from floats.
| 3452 | // the same result if we do this for floats, as if we do this for |
| 3453 | // doubles that were promoted from floats. |
| 3454 | struct WithinRelMatcher : MatcherBase<double> { |
| 3455 | WithinRelMatcher(double target, double epsilon); |
| 3456 | bool match(double const& matchee) const override; |
| 3457 | std::string describe() const override; |
| 3458 | private: |
| 3459 | double m_target; |
| 3460 | double m_epsilon; |
| 3461 | }; |
| 3462 | |
| 3463 | } // namespace Floating |
| 3464 |