Define Integer#remainder instead of Bignum#remainder.
* numeric.c (int_remainder): Define Integer#remainder. * bignum.c (rb_big_remainder): Don't define Bignum#remainder. * internal.h (rb_big_remainder): Declared. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ae225a2ca8
commit
635cff451f
@ -1,3 +1,11 @@
|
|||||||
|
Sat Apr 30 16:58:18 2016 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* numeric.c (int_remainder): Define Integer#remainder.
|
||||||
|
|
||||||
|
* bignum.c (rb_big_remainder): Don't define Bignum#remainder.
|
||||||
|
|
||||||
|
* internal.h (rb_big_remainder): Declared.
|
||||||
|
|
||||||
Sat Apr 30 15:29:24 2016 Tanaka Akira <akr@fsij.org>
|
Sat Apr 30 15:29:24 2016 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* numeric.c (rb_int_uminus): {Fixnum,Bignum}#-@ is unified into
|
* numeric.c (rb_int_uminus): {Fixnum,Bignum}#-@ is unified into
|
||||||
|
12
bignum.c
12
bignum.c
@ -6128,16 +6128,7 @@ rb_big_modulo(VALUE x, VALUE y)
|
|||||||
return bignorm(z);
|
return bignorm(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
VALUE
|
||||||
* call-seq:
|
|
||||||
* big.remainder(numeric) -> number
|
|
||||||
*
|
|
||||||
* Returns the remainder after dividing <i>big</i> by <i>numeric</i>.
|
|
||||||
*
|
|
||||||
* -1234567890987654321.remainder(13731) #=> -6966
|
|
||||||
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
|
|
||||||
*/
|
|
||||||
static VALUE
|
|
||||||
rb_big_remainder(VALUE x, VALUE y)
|
rb_big_remainder(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
VALUE z;
|
VALUE z;
|
||||||
@ -6888,7 +6879,6 @@ Init_Bignum(void)
|
|||||||
rb_define_method(rb_cBignum, "*", rb_big_mul, 1);
|
rb_define_method(rb_cBignum, "*", rb_big_mul, 1);
|
||||||
rb_define_method(rb_cBignum, "/", rb_big_div, 1);
|
rb_define_method(rb_cBignum, "/", rb_big_div, 1);
|
||||||
rb_define_method(rb_cBignum, "%", rb_big_modulo, 1);
|
rb_define_method(rb_cBignum, "%", rb_big_modulo, 1);
|
||||||
rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
|
|
||||||
|
|
||||||
rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
|
rb_define_method(rb_cBignum, "==", rb_big_eq, 1);
|
||||||
rb_define_method(rb_cBignum, ">", big_gt, 1);
|
rb_define_method(rb_cBignum, ">", big_gt, 1);
|
||||||
|
@ -786,6 +786,7 @@ VALUE rb_big_aref(VALUE x, VALUE y);
|
|||||||
VALUE rb_big_abs(VALUE x);
|
VALUE rb_big_abs(VALUE x);
|
||||||
VALUE rb_big_size_m(VALUE big);
|
VALUE rb_big_size_m(VALUE big);
|
||||||
VALUE rb_big_bit_length(VALUE big);
|
VALUE rb_big_bit_length(VALUE big);
|
||||||
|
VALUE rb_big_remainder(VALUE x, VALUE y);
|
||||||
|
|
||||||
/* class.c */
|
/* class.c */
|
||||||
VALUE rb_class_boot(VALUE);
|
VALUE rb_class_boot(VALUE);
|
||||||
|
35
numeric.c
35
numeric.c
@ -3536,6 +3536,40 @@ rb_int_modulo(VALUE x, VALUE y)
|
|||||||
return num_modulo(x, y);
|
return num_modulo(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* int.remainder(numeric) -> real
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Returns the remainder after dividing <i>big</i> by <i>numeric</i> as:
|
||||||
|
*
|
||||||
|
* x.remainder(y) means x-y*(x/y).truncate
|
||||||
|
*
|
||||||
|
* Examples
|
||||||
|
*
|
||||||
|
* 5.remainder(3) #=> 2
|
||||||
|
* -5.remainder(3) #=> -2
|
||||||
|
* 5.remainder(-3) #=> 2
|
||||||
|
* -5.remainder(-3) #=> -2
|
||||||
|
*
|
||||||
|
* -1234567890987654321.remainder(13731) #=> -6966
|
||||||
|
* -1234567890987654321.remainder(13731.24) #=> -9906.22531493148
|
||||||
|
*
|
||||||
|
* See Numeric#divmod.
|
||||||
|
*/
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
int_remainder(VALUE x, VALUE y)
|
||||||
|
{
|
||||||
|
if (FIXNUM_P(x)) {
|
||||||
|
return num_remainder(x, y);
|
||||||
|
}
|
||||||
|
else if (RB_TYPE_P(x, T_BIGNUM)) {
|
||||||
|
return rb_big_remainder(x, y);
|
||||||
|
}
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Document-method: Integer#divmod
|
* Document-method: Integer#divmod
|
||||||
* call-seq:
|
* call-seq:
|
||||||
@ -4843,6 +4877,7 @@ Init_Numeric(void)
|
|||||||
rb_define_method(rb_cInteger, "div", rb_int_idiv, 1);
|
rb_define_method(rb_cInteger, "div", rb_int_idiv, 1);
|
||||||
rb_define_method(rb_cFixnum, "%", fix_mod, 1);
|
rb_define_method(rb_cFixnum, "%", fix_mod, 1);
|
||||||
rb_define_method(rb_cInteger, "modulo", rb_int_modulo, 1);
|
rb_define_method(rb_cInteger, "modulo", rb_int_modulo, 1);
|
||||||
|
rb_define_method(rb_cInteger, "remainder", int_remainder, 1);
|
||||||
rb_define_method(rb_cInteger, "divmod", int_divmod, 1);
|
rb_define_method(rb_cInteger, "divmod", int_divmod, 1);
|
||||||
rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1);
|
rb_define_method(rb_cInteger, "fdiv", int_fdiv, 1);
|
||||||
rb_define_method(rb_cInteger, "**", rb_int_pow, 1);
|
rb_define_method(rb_cInteger, "**", rb_int_pow, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user