diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:11:42 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:11:42 +0000 |
commit | 622460dd007f6036c37ff53cf62a118af83cb4ea (patch) | |
tree | cbae23b08db864dddef841b385e5dd2a847b8c70 /numeric.c | |
parent | ce81367bc953fbe236dcd58f4145b6a95b02a9c5 (diff) | |
download | ruby-622460dd007f6036c37ff53cf62a118af83cb4ea.tar.gz |
* bignum.c (Bignum#even?, Bignum#odd?): remove definitions
because they are unified with Integer#even? and Integer#odd?.
* numeric.c (Fixnum#zero?, Fixnum#even?, Fixnum#odd?): remove
definitions because they are unified with Numeric#zero?,
Integer#even?, and Integer#odd?.
* numeric.c (num_zero_p, int_even_p, int_odd_p): treat Fixnum and
Bignum values directly.
* test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless
test case.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -605,7 +605,15 @@ num_abs(VALUE num) static VALUE num_zero_p(VALUE num) { - if (rb_equal(num, INT2FIX(0))) { + if (FIXNUM_P(num)) { + if (FIX2LONG(num) == 0) { + return Qtrue; + } + } + else if (RB_TYPE_P(num, T_BIGNUM)) { + return rb_bigzero_p(num); + } + else if (rb_equal(num, INT2FIX(0))) { return Qtrue; } return Qfalse; @@ -2670,7 +2678,15 @@ int_int_p(VALUE num) static VALUE int_odd_p(VALUE num) { - if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) { + if (FIXNUM_P(num)) { + if (num & 2) { + return Qtrue; + } + } + else if (RB_TYPE_P(num, T_BIGNUM)) { + return rb_big_odd_p(num); + } + else if (rb_funcall(num, '%', 1, INT2FIX(2)) != INT2FIX(0)) { return Qtrue; } return Qfalse; @@ -4268,9 +4284,6 @@ Init_Numeric(void) rb_define_method(rb_cFixnum, "to_f", fix_to_f, 0); rb_define_method(rb_cFixnum, "size", fix_size, 0); rb_define_method(rb_cFixnum, "bit_length", rb_fix_bit_length, 0); - rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0); - rb_define_method(rb_cFixnum, "odd?", fix_odd_p, 0); - rb_define_method(rb_cFixnum, "even?", fix_even_p, 0); rb_define_method(rb_cFixnum, "succ", fix_succ, 0); rb_cFloat = rb_define_class("Float", rb_cNumeric); |