|
|
@@ -5,6 +5,7 @@
|
|
|
|
|
|
#include <jvalidate/adapter.h>
|
|
|
#include <jvalidate/constraint/constraint.h>
|
|
|
+#include <jvalidate/detail/number.h>
|
|
|
#include <jvalidate/forward.h>
|
|
|
#include <limits>
|
|
|
|
|
|
@@ -39,12 +40,12 @@ public:
|
|
|
MultipleOfConstraint(double value) : value(value) {}
|
|
|
|
|
|
bool operator()(double arg) const {
|
|
|
- // TODO(samjaffe): ...
|
|
|
- if (std::isinf(arg)) {
|
|
|
- return false;
|
|
|
+ if (std::fabs(std::remainder(arg, value)) <= std::numeric_limits<double>::epsilon()) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- auto val = arg / value;
|
|
|
- return std::abs(std::floor(val) - val) < std::numeric_limits<double>::epsilon();
|
|
|
+
|
|
|
+ double const div = arg / value;
|
|
|
+ return std::isfinite(div) && detail::is_json_integer(div);
|
|
|
}
|
|
|
};
|
|
|
}
|