From f2852903ee26182e86399d64c3248e25d5d82e6f Mon Sep 17 00:00:00 2001 From: dhmemi Date: Sat, 23 Sep 2023 02:43:01 +0800 Subject: [PATCH] fix test case error when multipleOf is float but number is int --- src/json-validator.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/json-validator.cpp b/src/json-validator.cpp index ddbaaa1..43fc588 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -863,13 +863,9 @@ class numeric : public schema // multipleOf - if the remainder of the division is 0 -> OK bool violates_multiple_of(T x) const { - if constexpr (std::is_floating_point::value) { - auto multiple = x / multipleOf_.second; - auto error = std::abs((multiple - std::round(multiple)) * multipleOf_.second); - return error > std::numeric_limits::epsilon(); - } else { - return x % static_cast(multipleOf_.second) != 0; - } + auto multiple = x / multipleOf_.second; + auto error = std::abs((multiple - std::round(multiple)) * multipleOf_.second); + return error > std::numeric_limits::epsilon(); } void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override