From a1c65315402ed67448e3cf85eb1630c18861a0e2 Mon Sep 17 00:00:00 2001 From: garethsb-sony Date: Tue, 22 Jan 2019 12:50:03 +0000 Subject: [PATCH] [#48] Tolerable difference depends on input values (and since x must be larger than multipleOf value in order to succeed, that's the critical one) --- src/json-validator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 80c23db..797ea77 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -594,9 +594,9 @@ class numeric : public schema // multipleOf - if the remainder of the division is 0 -> OK bool violates_multiple_of(T x) const { - json::number_integer_t n = static_cast(x / multipleOf_.second); - double res = (x - n * multipleOf_.second); - return fabs(res) > std::numeric_limits::epsilon(); + double res = std::remainder(x, multipleOf_.second); + double eps = std::nextafter(x, 0) - x; + return std::fabs(res) > std::fabs(eps); } void validate(const json &instance, basic_error_handler &e) const override