Fix multipleOf in schema tests

This commit is contained in:
miloyip 2015-05-07 16:42:41 +08:00
parent e33049d288
commit 1948fb5786

View File

@ -16,7 +16,7 @@
#define RAPIDJSON_SCHEMA_H_
#include "document.h"
#include <cmath> // HUGE_VAL, fmod
#include <cmath> // HUGE_VAL, abs, floor
#if !defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
#define RAPIDJSON_SCHEMA_USE_STDREGEX 1
@ -35,7 +35,6 @@
#if defined(__GNUC__)
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
RAPIDJSON_DIAG_OFF(float-equal)
#endif
RAPIDJSON_NAMESPACE_BEGIN
@ -647,7 +646,13 @@ private:
bool CheckDouble(double d) const {
if (exclusiveMinimum_ ? d <= minimum_ : d < minimum_) return false;
if (exclusiveMaximum_ ? d >= maximum_ : d > maximum_) return false;
if (hasMultipleOf_ && std::fmod(d, multipleOf_) != 0.0) return false;
if (hasMultipleOf_) {
double a = std::abs(d), b = std::abs(multipleOf_);
double q = std::floor(a / b);
double r = a - q * b;
if (r > 0.0)
return false;
}
return true;
}