aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-01 11:35:57 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-01 11:35:57 +0000
commit7dd16046034ca43dc555141b1d3a57da2a57f04d (patch)
tree834a3b47d610e7af335bba13f20c2cd9df50bd5b /bignum.c
parentcec97f40f65bd5b7d775f6e1ec4ec425e6ae6095 (diff)
downloadruby-7dd16046034ca43dc555141b1d3a57da2a57f04d.tar.gz
* bignum.c (big2str_base_poweroftwo): Renamed from
big2str_base_powerof2. (rb_big2str_poweroftwo): New function for test. (big2str_generic): Extracted from rb_big2str1. (rb_big2str_generic): New function for test. * internal.h (rb_big2str_poweroftwo): Declared. (rb_big2str_generic): Ditto. * ext/-test-/bignum/big2str.c: New file. * test/-ext-/bignum/test_big2str.rb: New file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c82
1 files changed, 54 insertions, 28 deletions
diff --git a/bignum.c b/bignum.c
index 91e931e36c..971678b3d3 100644
--- a/bignum.c
+++ b/bignum.c
@@ -4354,7 +4354,7 @@ big2str_karatsuba(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, size_t wn,
}
static VALUE
-big2str_base_powerof2(VALUE x, int base)
+big2str_base_poweroftwo(VALUE x, int base)
{
int word_numbits = ffs(base) - 1;
size_t numwords;
@@ -4384,38 +4384,18 @@ big2str_base_powerof2(VALUE x, int base)
return result;
}
+VALUE
+rb_big2str_poweroftwo(VALUE x, int base)
+{
+ return big2str_base_poweroftwo(x, base);
+}
+
static VALUE
-rb_big2str1(VALUE x, int base)
+big2str_generic(VALUE x, int base, BDIGIT *xds, size_t xn)
{
struct big2str_struct b2s_data;
int power_level;
VALUE power;
- BDIGIT *xds;
- size_t xn;
-
- if (FIXNUM_P(x)) {
- return rb_fix2str(x, base);
- }
-
- xds = BDIGITS(x);
- xn = RBIGNUM_LEN(x);
- BARY_TRUNC(xds, xn);
-
- if (xn == 0) {
- return rb_usascii_str_new2("0");
- }
-
- if (base < 2 || 36 < base)
- rb_raise(rb_eArgError, "invalid radix %d", base);
-
- if (xn >= LONG_MAX/BITSPERDIG) {
- rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
- }
-
- if (POW2_P(base)) {
- /* base == 2 || base == 4 || base == 8 || base == 16 || base == 32 */
- return big2str_base_powerof2(x, base);
- }
power_level = 0;
power = power_cache_get_power(base, power_level, NULL);
@@ -4469,6 +4449,52 @@ rb_big2str1(VALUE x, int base)
return b2s_data.result;
}
+VALUE
+rb_big2str_generic(VALUE x, int base)
+{
+ BDIGIT *xds;
+ size_t xn;
+
+ xds = BDIGITS(x);
+ xn = RBIGNUM_LEN(x);
+ BARY_TRUNC(xds, xn);
+
+ return big2str_generic(x, base, xds, xn);
+}
+
+static VALUE
+rb_big2str1(VALUE x, int base)
+{
+ BDIGIT *xds;
+ size_t xn;
+
+ if (FIXNUM_P(x)) {
+ return rb_fix2str(x, base);
+ }
+
+ xds = BDIGITS(x);
+ xn = RBIGNUM_LEN(x);
+ BARY_TRUNC(xds, xn);
+
+ if (xn == 0) {
+ return rb_usascii_str_new2("0");
+ }
+
+ if (base < 2 || 36 < base)
+ rb_raise(rb_eArgError, "invalid radix %d", base);
+
+ if (xn >= LONG_MAX/BITSPERDIG) {
+ rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
+ }
+
+ if (POW2_P(base)) {
+ /* base == 2 || base == 4 || base == 8 || base == 16 || base == 32 */
+ return big2str_base_poweroftwo(x, base);
+ }
+
+ return big2str_generic(x, base, xds, xn);
+}
+
/* deprecated */
VALUE
rb_big2str0(VALUE x, int base, int trim)