summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 15:55:07 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-02 15:55:07 +0000
commitebbaec9696e6e567770a39adf0c25f92a82200c4 (patch)
treeb896fa34b5ee90490b1be59d24160fbae879cddc
parent633fd55c4cc8b11af9dac78223a1e76080058525 (diff)
* bignum.c (rb_big2str1): Simplify power_level calculation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--bignum.c28
2 files changed, 18 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 864540c..0f6cdd5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Aug 3 00:52:43 2013 Tanaka Akira <akr@fsij.org>
+
+ * bignum.c (rb_big2str1): Simplify power_level calculation.
+
Sat Aug 3 00:34:20 2013 Masaki Matsushita <glass.saga@gmail.com>
* array.c (rb_ary_zip): use rb_ary_new2() to create buffer
diff --git a/bignum.c b/bignum.c
index ded2d6b..faedade 100644
--- a/bignum.c
+++ b/bignum.c
@@ -4308,7 +4308,9 @@ big2str_karatsuba(struct big2str_struct *b2s, VALUE x,
/*
* Precondition:
- * abs(x) < maxpow_in_bdigit_dbl(base, &numdigits)**(2**power_level)
+ * abs(x) < maxpow**(2**power_level)
+ * where
+ * maxpow = maxpow_in_bdigit_dbl(base, &numdigits)
*
* This function generates sequence of zeros, and then stringized abs(x) into b2s->ptr.
*
@@ -4453,22 +4455,20 @@ rb_big2str1(VALUE x, int base)
power = power_cache_get_power(base, power_level, NULL);
}
assert(power_level != MAX_BIG2STR_TABLE_ENTRIES);
- if (FIX2LONG(bary_cmp(BDIGITS(x), RBIGNUM_LEN(x), BDIGITS(power), RBIGNUM_LEN(power))) >= 0) {
- power_level++;
- }
-#ifndef NDEBUG
- if (0 < power_level) {
- VALUE power1 = power_cache_get_power(base, power_level-1, NULL);
- assert(FIX2LONG(bary_cmp(BDIGITS(x), RBIGNUM_LEN(x), BDIGITS(power1), RBIGNUM_LEN(power1))) >= 0);
+ if (RBIGNUM_LEN(power) <= RBIGNUM_LEN(x)) {
/*
- {
- VALUE power0 = power_cache_get_power(base, power_level, NULL);
- assert(FIX2LONG(bary_cmp(BDIGITS(x), RBIGNUM_LEN(x), BDIGITS(power0), RBIGNUM_LEN(power0))) < 0);
- }
- */
+ * This increment guarantees x < power_cache_get_power(base, power_level)
+ * without invoking it actually.
+ * (power_cache_get_power(base, power_level) can be slow and not used
+ * in big2str_karatsuba.)
+ *
+ * Although it is possible that x < power_cache_get_power(base, power_level-1),
+ * it is no problem because big2str_karatsuba checks it and
+ * doesn't affect the result when b2s_data.ptr is NULL.
+ */
+ power_level++;
}
-#endif
b2s_data.negative = RBIGNUM_NEGATIVE_P(x);
b2s_data.base = base;