* 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
This commit is contained in:
parent
633fd55c4c
commit
ebbaec9696
@ -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>
|
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
|
* array.c (rb_ary_zip): use rb_ary_new2() to create buffer
|
||||||
|
30
bignum.c
30
bignum.c
@ -4308,7 +4308,9 @@ big2str_karatsuba(struct big2str_struct *b2s, VALUE x,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Precondition:
|
* 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.
|
* This function generates sequence of zeros, and then stringized abs(x) into b2s->ptr.
|
||||||
*
|
*
|
||||||
@ -4453,23 +4455,21 @@ rb_big2str1(VALUE x, int base)
|
|||||||
power = power_cache_get_power(base, power_level, NULL);
|
power = power_cache_get_power(base, power_level, NULL);
|
||||||
}
|
}
|
||||||
assert(power_level != MAX_BIG2STR_TABLE_ENTRIES);
|
assert(power_level != MAX_BIG2STR_TABLE_ENTRIES);
|
||||||
if (FIX2LONG(bary_cmp(BDIGITS(x), RBIGNUM_LEN(x), BDIGITS(power), RBIGNUM_LEN(power))) >= 0) {
|
|
||||||
|
if (RBIGNUM_LEN(power) <= RBIGNUM_LEN(x)) {
|
||||||
|
/*
|
||||||
|
* 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++;
|
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);
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
b2s_data.negative = RBIGNUM_NEGATIVE_P(x);
|
b2s_data.negative = RBIGNUM_NEGATIVE_P(x);
|
||||||
b2s_data.base = base;
|
b2s_data.base = base;
|
||||||
b2s_data.hbase = maxpow_in_bdigit(base, &b2s_data.hbase_numdigits);
|
b2s_data.hbase = maxpow_in_bdigit(base, &b2s_data.hbase_numdigits);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user