зеркало из https://github.com/github/ruby.git
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54176 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a22ff208e5
Коммит
ad0b5ebc50
|
@ -1,3 +1,10 @@
|
|||
Fri Mar 18 21:57:00 2016 Kenta Murata <mrkn@mrkn.jp>
|
||||
|
||||
* 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@mrkn.jp>
|
||||
|
||||
* numeric.c (int_to_s): Move from flo_to_s.
|
||||
|
|
31
bignum.c
31
bignum.c
|
@ -4966,35 +4966,6 @@ rb_big2str(VALUE x, int base)
|
|||
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)
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -2959,6 +2959,7 @@ rb_fix2str(VALUE x, int base)
|
|||
* 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)
|
|||
base = NUM2INT(b);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче