浏览代码

Updating compare to take an offset number of cells.

Samuel Jaffe 8 年之前
父节点
当前提交
67269aec3d
共有 2 个文件被更改,包括 7 次插入7 次删除
  1. 1 1
      include/bignum_helper.h
  2. 6 6
      src/bignum_helper.cpp

+ 1 - 1
include/bignum_helper.h

@@ -12,7 +12,7 @@
 namespace math { namespace detail {
   using data_type = std::vector<int32_t>;
   // 1 => GREATER, 0 => EQUAL, -1 => LESS
-  int compare(data_type const & rhs, data_type const & lhs);
+  int compare(data_type const & rhs, data_type const & lhs, size_t offset = 0);
   void add(data_type & rhs, data_type const & lhs, size_t offset = 0);
   void subtract_nounderflow(data_type & rhs, data_type const & lhs, size_t offset = 0);
   void multiply(data_type & rhs, data_type const & lhs);

+ 6 - 6
src/bignum_helper.cpp

@@ -18,13 +18,13 @@ namespace {
 }
 
 namespace math { namespace detail {
-#define IMPL_COMPARE(expr) \
-  if (rhs expr < lhs expr) return -1; \
-  else if (lhs expr < rhs expr) return 1
-  int compare(data_type const & rhs, data_type const & lhs) {
-    IMPL_COMPARE(.size());
+#define IMPL_COMPARE(rexpr, lexpr) \
+  if (rhs rexpr < lhs lexpr) return -1; \
+  else if (lhs lexpr < rhs rexpr) return 1
+  int compare(data_type const & rhs, data_type const & lhs, size_t offset) {
+    IMPL_COMPARE(.size(), .size()+offset);
     for (size_t i = rhs.size(); i > 0; --i) {
-      IMPL_COMPARE([i-1]);
+      IMPL_COMPARE([i-1], [i+offset-1]);
     }
     return 0;
   }