Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_matchers_floating.h
Go to the documentation of this file.
1/*
2 * Created by Martin on 07/11/2017.
3 *
4 * Distributed under the Boost Software License, Version 1.0. (See accompanying
5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7#ifndef TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED
8#define TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED
9
10#include "catch_matchers.h"
11
12#include <type_traits>
13#include <cmath>
14
15namespace Catch {
16namespace Matchers {
17
18 namespace Floating {
19
20 enum class FloatingPointKind : uint8_t;
21
22 struct WithinAbsMatcher : MatcherBase<double> {
23 WithinAbsMatcher(double target, double margin);
24 bool match(double const& matchee) const override;
25 std::string describe() const override;
26 private:
27 double m_target;
28 double m_margin;
29 };
30
31 struct WithinUlpsMatcher : MatcherBase<double> {
32 WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType);
33 bool match(double const& matchee) const override;
34 std::string describe() const override;
35 private:
36 double m_target;
37 int m_ulps;
38 FloatingPointKind m_type;
39 };
40
41
42 } // namespace Floating
43
44 // The following functions create the actual matcher objects.
45 // This allows the types to be inferred
46 Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff);
47 Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff);
48 Floating::WithinAbsMatcher WithinAbs(double target, double margin);
49
50} // namespace Matchers
51} // namespace Catch
52
53#endif // TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED
Floating::WithinAbsMatcher WithinAbs(double target, double margin)
Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff)
unsigned char uint8_t
Definition stdint.h:124
bool match(double const &matchee) const override
WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType)
bool match(double const &matchee) const override