[#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)

This commit is contained in:
garethsb-sony 2019-01-22 12:50:03 +00:00
parent 57e470513b
commit 60bc33a1c9

View File

@ -594,9 +594,9 @@ class numeric : public schema
// multipleOf - if the remainder of the division is 0 -> OK // multipleOf - if the remainder of the division is 0 -> OK
bool violates_multiple_of(T x) const bool violates_multiple_of(T x) const
{ {
json::number_integer_t n = static_cast<json::number_integer_t>(x / multipleOf_.second); double res = std::remainder(x, multipleOf_.second);
double res = (x - n * multipleOf_.second); double eps = std::nextafter(x, 0) - x;
return fabs(res) > std::numeric_limits<json::number_float_t>::epsilon(); return std::fabs(res) > std::fabs(eps);
} }
void validate(const json &instance, basic_error_handler &e) const override void validate(const json &instance, basic_error_handler &e) const override