ruby-changes:42102
From: mrkn <ko1@a...>
Date: Fri, 18 Mar 2016 21:57:45 +0900 (JST)
Subject: [ruby-changes:42102] mrkn:r54176 (trunk): * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition because
mrkn 2016-03-18 21:57:40 +0900 (Fri, 18 Mar 2016) New Revision: 54176 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54176 Log: * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition because it is unified with Integer#to_s. * numeric.c (int_to_s): treat Bignum values directly. Modified files: trunk/ChangeLog trunk/bignum.c trunk/numeric.c Index: ChangeLog =================================================================== --- ChangeLog (revision 54175) +++ ChangeLog (revision 54176) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Mar 18 21:57:00 2016 Kenta Murata <mrkn@m...> + + * bignum.c (rb_big_to_s, Bignum#to_s): remove its definition because + it is unified with Integer#to_s. + + * numeric.c (int_to_s): treat Bignum values directly. + Fri Mar 18 21:30:00 2016 Kenta Murata <mrkn@m...> * numeric.c (int_to_s): Move from flo_to_s. Index: bignum.c =================================================================== --- bignum.c (revision 54175) +++ bignum.c (revision 54176) @@ -4966,35 +4966,6 @@ rb_big2str(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4966 return rb_big2str1(x, base); } -/* - * call-seq: - * big.to_s(base=10) -> string - * - * Returns a string containing the representation of <i>big</i> radix - * <i>base</i> (2 through 36). - * - * 12345654321.to_s #=> "12345654321" - * 12345654321.to_s(2) #=> "1011011111110110111011110000110001" - * 12345654321.to_s(8) #=> "133766736061" - * 12345654321.to_s(16) #=> "2dfdbbc31" - * 78546939656932.to_s(36) #=> "rubyrules" - */ - -static VALUE -rb_big_to_s(int argc, VALUE *argv, VALUE x) -{ - int base; - - if (argc == 0) base = 10; - else { - VALUE b; - - rb_scan_args(argc, argv, "01", &b); - base = NUM2INT(b); - } - return rb_big2str(x, base); -} - static unsigned long big2ulong(VALUE x, const char *type) { @@ -7045,8 +7016,6 @@ Init_Bignum(void) https://github.com/ruby/ruby/blob/trunk/bignum.c#L7016 { rb_cBignum = rb_define_class("Bignum", rb_cInteger); - rb_define_method(rb_cBignum, "to_s", rb_big_to_s, -1); - rb_define_alias(rb_cBignum, "inspect", "to_s"); rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1); rb_define_method(rb_cBignum, "-@", rb_big_uminus, 0); rb_define_method(rb_cBignum, "+", rb_big_plus, 1); Index: numeric.c =================================================================== --- numeric.c (revision 54175) +++ numeric.c (revision 54176) @@ -2959,6 +2959,7 @@ rb_fix2str(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2959 * 12345.to_s(10) #=> "12345" * 12345.to_s(16) #=> "3039" * 12345.to_s(36) #=> "9ix" + * 78546939656932.to_s(36) #=> "rubyrules" * */ static VALUE @@ -2974,7 +2975,14 @@ int_to_s(int argc, VALUE *argv, VALUE x) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2975 base = NUM2INT(b); } - return rb_fix2str(x, base); + if (FIXNUM_P(x)) { + return rb_fix2str(x, base); + } + else if (RB_TYPE_P(x, T_BIGNUM)) { + return rb_big2str(x, base); + } + + return rb_any_to_s(x); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/