aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-26 11:47:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-26 11:47:14 +0000
commit8f045eddb2dcd171b98a4dd6b018441acf4b1048 (patch)
tree8c7291b6f8b3dc6e7d2e820bcfcb70ca8616fb56
parent05bd6f83690ccd9cec4728cd23a4a66c995abcc2 (diff)
downloadruby-8f045eddb2dcd171b98a4dd6b018441acf4b1048.tar.gz
{Fixnum,Bignum}#size is unified into Integer.
* numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer. * bignum.c (rb_big_size_m): Don't define Bignum#size. * internal.h (rb_big_size_m): Declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--bignum.c15
-rw-r--r--internal.h1
-rw-r--r--numeric.c23
4 files changed, 29 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 3b8687fd55..2133a36c48 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Tue Apr 26 20:46:16 2016 Tanaka Akira <akr@fsij.org>
+
+ * numeric.c (int_size): {Fixnum,Bignum}#size is unified into Integer.
+
+ * bignum.c (rb_big_size_m): Don't define Bignum#size.
+
+ * internal.h (rb_big_size_m): Declared.
+
Tue Apr 26 20:09:08 2016 Tanaka Akira <akr@fsij.org>
* numeric.c (rb_int_bit_length): {Fixnum,Bignum}#bit_length is
diff --git a/bignum.c b/bignum.c
index 5ce95eea16..335304204e 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6902,19 +6902,7 @@ rb_big_size(VALUE big)
return BIGSIZE(big);
}
-/*
- * call-seq:
- * big.size -> integer
- *
- * Returns the number of bytes in the machine representation of
- * <i>big</i>.
- *
- * (256**10 - 1).size #=> 12
- * (256**20 - 1).size #=> 20
- * (256**40 - 1).size #=> 40
- */
-
-static VALUE
+VALUE
rb_big_size_m(VALUE big)
{
return SIZET2NUM(rb_big_size(big));
@@ -7043,7 +7031,6 @@ Init_Bignum(void)
rb_define_method(rb_cBignum, "<", big_lt, 1);
rb_define_method(rb_cBignum, "<=", big_le, 1);
rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
- rb_define_method(rb_cBignum, "size", rb_big_size_m, 0);
#ifdef USE_GMP
/* The version of loaded GMP. */
diff --git a/internal.h b/internal.h
index a2250d5649..c04a0c36e3 100644
--- a/internal.h
+++ b/internal.h
@@ -779,6 +779,7 @@ VALUE rb_integer_float_cmp(VALUE x, VALUE y);
VALUE rb_integer_float_eq(VALUE x, VALUE y);
VALUE rb_cstr_parse_inum(const char *str, ssize_t len, char **endp, int base);
VALUE rb_big_abs(VALUE x);
+VALUE rb_big_size_m(VALUE big);
VALUE rb_big_bit_length(VALUE big);
/* class.c */
diff --git a/numeric.c b/numeric.c
index 7d3ad34ebb..4ec8f3e0c3 100644
--- a/numeric.c
+++ b/numeric.c
@@ -4104,21 +4104,36 @@ int_abs(VALUE num)
return Qnil;
}
+static VALUE
+fix_size(VALUE fix)
+{
+ return INT2FIX(sizeof(long));
+}
+
/*
* call-seq:
- * fix.size -> fixnum
+ * int.size -> int
*
* Returns the number of bytes in the machine representation of +fix+.
*
* 1.size #=> 4
* -1.size #=> 4
* 2147483647.size #=> 4
+ * (256**10 - 1).size #=> 12
+ * (256**20 - 1).size #=> 20
+ * (256**40 - 1).size #=> 40
*/
static VALUE
-fix_size(VALUE fix)
+int_size(VALUE num)
{
- return INT2FIX(sizeof(long));
+ if (FIXNUM_P(num)) {
+ return fix_size(num);
+ }
+ else if (RB_TYPE_P(num, T_BIGNUM)) {
+ return rb_big_size_m(num);
+ }
+ return Qnil;
}
static VALUE
@@ -4669,7 +4684,7 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "<<", rb_fix_lshift, 1);
rb_define_method(rb_cFixnum, ">>", rb_fix_rshift, 1);
- rb_define_method(rb_cFixnum, "size", fix_size, 0);
+ rb_define_method(rb_cInteger, "size", int_size, 0);
rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0);
rb_define_method(rb_cFixnum, "succ", fix_succ, 0);