diff options
author | Tim King <taking@cs.nyu.edu> | 2012-11-26 21:38:28 +0000 |
---|---|---|
committer | Tim King <taking@cs.nyu.edu> | 2012-11-26 21:38:28 +0000 |
commit | 1e4c37a3ef7b1c16914b181c189716aa4a3df6b8 (patch) | |
tree | e8e905504deaface2e563adb54564d04cf7e568b /src/util | |
parent | a7aad4ae3a1cd80f0e035e1a77b8e42c38c99c8d (diff) |
Improved implementation of Integer::length() with CLN enabled. Additional tests to sanity check both versions CLN and GMP versions of length.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/integer_cln_imp.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util/integer_cln_imp.h b/src/util/integer_cln_imp.h index 78b775bee..ad21be287 100644 --- a/src/util/integer_cln_imp.h +++ b/src/util/integer_cln_imp.h @@ -456,7 +456,14 @@ public: if(s == 0){ return 1; }else if(s < 0){ - return cln::integer_length(-d_value); + size_t len = cln::integer_length(d_value); + /*If this is -2^n, return len+1 not len to stay consistent with the definition above! + * From CLN's documentation of integer_length: + * This is the smallest n >= 0 such that -2^n <= x < 2^n. + * If x > 0, this is the unique n > 0 such that 2^(n-1) <= x < 2^n. + */ + size_t ord2 = cln::ord2(d_value); + return (len == ord2) ? (len + 1) : len; }else{ return cln::integer_length(d_value); } |