Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal/catch_matchers_floating.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-10-05 20:58:11 +0200
committerMartin Hořeňovský2019-10-05 21:03:46 +0200
commit4bd2c3ad6ab0bcdecf9101dcf7f5968901f68351 (patch)
tree0307a69931a62cdcc1707231bdcbef59f243211e /include/internal/catch_matchers_floating.cpp
parentc38a5caa2ebf0738e468f419c4d3ed857001cfb0 (diff)
downloadcatch3-4bd2c3ad6ab0bcdecf9101dcf7f5968901f68351.tar.gz
Fix compilation error with CATCH_CONFIG_GLOBAL_NEXTAFTER
Wrong nesting of namespaces resulted in the `Catch` namespace being ambigous between `::Catch` and `::{anon}::Catch` namespaces. This should fix it. Closes #1761
Diffstat (limited to 'include/internal/catch_matchers_floating.cpp')
-rw-r--r--include/internal/catch_matchers_floating.cpp89
1 files changed, 47 insertions, 42 deletions
diff --git a/include/internal/catch_matchers_floating.cpp b/include/internal/catch_matchers_floating.cpp
index 8de8c7aa..c9a79ad1 100644
--- a/include/internal/catch_matchers_floating.cpp
+++ b/include/internal/catch_matchers_floating.cpp
@@ -22,55 +22,51 @@
namespace Catch {
-namespace Matchers {
-namespace Floating {
-enum class FloatingPointKind : uint8_t {
- Float,
- Double
-};
-}
-}
-}
-
namespace {
-int32_t convert(float f) {
- static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated");
- int32_t i;
- std::memcpy(&i, &f, sizeof(f));
- return i;
-}
-
-int64_t convert(double d) {
- static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated");
- int64_t i;
- std::memcpy(&i, &d, sizeof(d));
- return i;
-}
+ int32_t convert(float f) {
+ static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated");
+ int32_t i;
+ std::memcpy(&i, &f, sizeof(f));
+ return i;
+ }
-template <typename FP>
-bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
- // Comparison with NaN should always be false.
- // This way we can rule it out before getting into the ugly details
- if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
- return false;
+ int64_t convert(double d) {
+ static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated");
+ int64_t i;
+ std::memcpy(&i, &d, sizeof(d));
+ return i;
}
- auto lc = convert(lhs);
- auto rc = convert(rhs);
+ template <typename FP>
+ bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
+ // Comparison with NaN should always be false.
+ // This way we can rule it out before getting into the ugly details
+ if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
+ return false;
+ }
+
+ auto lc = convert(lhs);
+ auto rc = convert(rhs);
- if ((lc < 0) != (rc < 0)) {
- // Potentially we can have +0 and -0
- return lhs == rhs;
- }
+ if ((lc < 0) != (rc < 0)) {
+ // Potentially we can have +0 and -0
+ return lhs == rhs;
+ }
- auto ulpDiff = std::abs(lc - rc);
- return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
+ auto ulpDiff = std::abs(lc - rc);
+ return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
+ }
}
#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
-namespace Catch {
+#if defined(__clang__)
+#pragma clang diagnostic push
+// The long double overload is currently unused
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
float nextafter(float x, float y) {
return ::nextafterf(x, y);
}
@@ -82,10 +78,15 @@ namespace Catch {
long double nextafter(long double x, long double y) {
return ::nextafterl(x, y);
}
-} // end namespace Catch
+#if defined(__clang__)
+#pragma clang diagnostic pop
#endif
+#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^
+
+namespace {
+
template <typename FP>
FP step(FP start, FP direction, uint64_t steps) {
for (uint64_t i = 0; i < steps; ++i) {
@@ -97,13 +98,17 @@ FP step(FP start, FP direction, uint64_t steps) {
}
return start;
}
-
} // end anonymous namespace
-
-namespace Catch {
namespace Matchers {
namespace Floating {
+
+ enum class FloatingPointKind : uint8_t {
+ Float,
+ Double
+ };
+
+
WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
:m_target{ target }, m_margin{ margin } {
CATCH_ENFORCE(margin >= 0, "Invalid margin: " << margin << '.'