From c4107e71c568250324a78634afb85fa1b19e21d0 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 3 Jul 2013 03:08:52 +0000 Subject: * 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 --- ChangeLog | 5 +++++ bignum.c | 38 +++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index b7f2ac3e3e..f2785796c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 3 12:06:42 2013 Tanaka Akira + + * bignum.c (maxpow_in_bdigit): Renamed from calc_hbase and return + maxpow. + Tue Jul 2 23:47:50 2013 Tanaka Akira * bignum.c (roomof): Cast to long. diff --git a/bignum.c b/bignum.c index 20bc8512cd..3d66c8a1ad 100644 --- a/bignum.c +++ b/bignum.c @@ -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); -- cgit v1.2.3