diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-03 03:08:52 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-03 03:08:52 +0000 |
commit | c4107e71c568250324a78634afb85fa1b19e21d0 (patch) | |
tree | d8a3536619743d56a4fa7220ac168ae5a0dc5e5d | |
parent | c78826190f5af562cb725c050ff09d439e27b5eb (diff) | |
download | ruby-c4107e71c568250324a78634afb85fa1b19e21d0.tar.gz |
* bignum.c (maxpow_in_bdigit): Renamed from calc_hbase and return
maxpow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 38 |
2 files changed, 24 insertions, 19 deletions
@@ -1,3 +1,8 @@ +Wed Jul 3 12:06:42 2013 Tanaka Akira <akr@fsij.org> + + * bignum.c (maxpow_in_bdigit): Renamed from calc_hbase and return + maxpow. + Tue Jul 2 23:47:50 2013 Tanaka Akira <akr@fsij.org> * bignum.c (roomof): Cast to long. @@ -107,7 +107,6 @@ static void bary_add(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds static int bary_pack(int sign, BDIGIT *ds, size_t num_bdigits, void *words, size_t numwords, size_t wordsize, size_t nails, int flags); static int bary_2comp(BDIGIT *ds, size_t n); -static void calc_hbase(int base, BDIGIT *hbase_p, int *hbase_numdigits_p); static VALUE bigsqr_fast(VALUE x); static VALUE bigmul0(VALUE x, VALUE y); @@ -238,6 +237,24 @@ maxpow_in_bdigit_dbl(int base, int *exp_ret) return maxpow; } +static BDIGIT +maxpow_in_bdigit(int base, int *exp_ret) +{ + BDIGIT maxpow; + int exponent; + + maxpow = base; + exponent = 1; + while (maxpow <= BDIGMAX / base) { + maxpow *= base; + exponent++; + } + + *exp_ret = exponent; + return maxpow; +} + + static int bary_zero_p(BDIGIT *xds, size_t nx) { @@ -2506,23 +2523,6 @@ big2str_karatsuba(VALUE x, int base, char* ptr, return lh + ll; } -static void -calc_hbase(int base, BDIGIT *hbase_p, int *hbase_numdigits_p) -{ - BDIGIT hbase; - int hbase_numdigits; - - hbase = base; - hbase_numdigits = 1; - while (hbase <= BDIGMAX / base) { - hbase *= base; - hbase_numdigits++; - } - - *hbase_p = hbase; - *hbase_numdigits_p = hbase_numdigits; -} - static VALUE big2str_base_powerof2(VALUE x, size_t len, int base, int trim) { @@ -2586,7 +2586,7 @@ rb_big2str0(VALUE x, int base, int trim) ptr = RSTRING_PTR(ss); ptr[0] = RBIGNUM_SIGN(x) ? '+' : '-'; - calc_hbase(base, &hbase, &hbase_numdigits); + hbase = maxpow_in_bdigit(base, &hbase_numdigits); off = !(trim && RBIGNUM_SIGN(x)); /* erase plus sign if trim */ xx = rb_big_clone(x); RBIGNUM_SET_SIGN(xx, 1); |