From cd549e0c9d4d0c8b88986d2c2d392e69de2bced9 Mon Sep 17 00:00:00 2001 From: "John K. Luebs" Date: Fri, 8 Mar 2024 16:56:22 -0600 Subject: [PATCH] Fix minor defect in kiwi Constraint::violated If epsilon is used for ==, it should be used for <= and >=. --- kiwi/kiwi/constraint.h | 4 ++-- kiwi/kiwi/util.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kiwi/kiwi/constraint.h b/kiwi/kiwi/constraint.h index e772036..c6eae68 100644 --- a/kiwi/kiwi/constraint.h +++ b/kiwi/kiwi/constraint.h @@ -63,8 +63,8 @@ class ConstraintData : public SharedData switch (m_op) { case OP_EQ: return !impl::nearZero(m_expression.value()); - case OP_GE: return m_expression.value() < 0.0; - case OP_LE: return m_expression.value() > 0.0; + case OP_GE: return m_expression.value() < impl::EPSILON; + case OP_LE: return m_expression.value() > impl::EPSILON; } std::abort(); } diff --git a/kiwi/kiwi/util.h b/kiwi/kiwi/util.h index 560a43a..1fd2723 100644 --- a/kiwi/kiwi/util.h +++ b/kiwi/kiwi/util.h @@ -13,10 +13,11 @@ namespace kiwi namespace impl { +constexpr const double EPSILON = 1.0e-8; + inline bool nearZero(double value) { - const double eps = 1.0e-8; - return value < 0.0 ? -value < eps : value < eps; + return value < 0.0 ? -value < EPSILON : value < EPSILON; } } // namespace impl