File indexing completed on 2025-01-30 10:02:51
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
0009 #define CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
0010
0011 #include <catch2/matchers/catch_matchers.hpp>
0012
0013 namespace Catch {
0014 namespace Matchers {
0015
0016 namespace Detail {
0017 enum class FloatingPointKind : uint8_t;
0018 }
0019
0020 class WithinAbsMatcher final : public MatcherBase<double> {
0021 public:
0022 WithinAbsMatcher(double target, double margin);
0023 bool match(double const& matchee) const override;
0024 std::string describe() const override;
0025 private:
0026 double m_target;
0027 double m_margin;
0028 };
0029
0030
0031 WithinAbsMatcher WithinAbs( double target, double margin );
0032
0033
0034
0035 class WithinUlpsMatcher final : public MatcherBase<double> {
0036 public:
0037 WithinUlpsMatcher( double target,
0038 uint64_t ulps,
0039 Detail::FloatingPointKind baseType );
0040 bool match(double const& matchee) const override;
0041 std::string describe() const override;
0042 private:
0043 double m_target;
0044 uint64_t m_ulps;
0045 Detail::FloatingPointKind m_type;
0046 };
0047
0048
0049 WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
0050
0051 WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 class WithinRelMatcher final : public MatcherBase<double> {
0062 public:
0063 WithinRelMatcher( double target, double epsilon );
0064 bool match(double const& matchee) const override;
0065 std::string describe() const override;
0066 private:
0067 double m_target;
0068 double m_epsilon;
0069 };
0070
0071
0072 WithinRelMatcher WithinRel(double target, double eps);
0073
0074 WithinRelMatcher WithinRel(double target);
0075
0076 WithinRelMatcher WithinRel(float target, float eps);
0077
0078 WithinRelMatcher WithinRel(float target);
0079
0080
0081
0082 class IsNaNMatcher final : public MatcherBase<double> {
0083 public:
0084 IsNaNMatcher() = default;
0085 bool match( double const& matchee ) const override;
0086 std::string describe() const override;
0087 };
0088
0089 IsNaNMatcher IsNaN();
0090
0091 }
0092 }
0093
0094 #endif