Pārlūkot izejas kodu

refactor: support for optional float_overflow

Sam Jaffe 1 gadu atpakaļ
vecāks
revīzija
05ee4c9632
2 mainītis faili ar 7 papildinājumiem un 7 dzēšanām
  1. 1 2
      Makefile
  2. 6 5
      include/jvalidate/constraint/number_constraint.h

+ 1 - 2
Makefile

@@ -24,8 +24,7 @@ TEST_SOURCES := $(wildcard $(TEST_DIR)*.cxx)
 TEST_OBJECTS := $(patsubst %.cxx, .build/%.o, $(TEST_SOURCES))
 TEST_BINARIES := .build/bin/selfvalidate
 
-EXCLUDED_TESTS := format* content ecmascript_regex \
-		  float_overflow zeroTerminatedFloats
+EXCLUDED_TESTS := format* content ecmascript_regex zeroTerminatedFloats
 EXCLUDED_TESTS := $(shell printf ":*optional_%s" $(EXCLUDED_TESTS) | cut -c2-)
 
 all: run-test

+ 6 - 5
include/jvalidate/constraint/number_constraint.h

@@ -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);
   }
 };
 }