diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:15:33 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-17 17:15:33 +0000 |
commit | 0a607bc8f8101190e0684df2e4cea08cc562a5b0 (patch) | |
tree | ccd1476c348be3f9ae09e5741e9d1e5e7cb38ba2 | |
parent | aa1ea07d37a6684f310fcc0103f9e1fd8a28921c (diff) | |
download | ruby-0a607bc8f8101190e0684df2e4cea08cc562a5b0.tar.gz |
* numeric.c (int_even_p): treat Fixnum and Bignum values directly.
I forgot include this commit in the previous one.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54165 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | numeric.c | 10 |
2 files changed, 14 insertions, 2 deletions
@@ -1,3 +1,7 @@ +Fri Mar 18 02:15:00 2016 Kenta Murata <mrkn@mrkn.jp> + + * numeric.c (int_even_p): treat Fixnum and Bignum values directly. + Fri Mar 18 02:07:00 2016 Kenta Murata <mrkn@mrkn.jp> * bignum.c (Bignum#even?, Bignum#odd?): remove definitions @@ -7,7 +11,7 @@ Fri Mar 18 02:07:00 2016 Kenta Murata <mrkn@mrkn.jp> 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 + * numeric.c (num_zero_p, int_odd_p): treat Fixnum and Bignum values directly. * test/ruby/test_integer.rb (test_odd_p_even_p): remove meaningless @@ -2702,7 +2702,15 @@ int_odd_p(VALUE num) static VALUE int_even_p(VALUE num) { - if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) { + if (FIXNUM_P(num)) { + if ((num & 2) == 0) { + return Qtrue; + } + } + else if (RB_TYPE_P(num, T_BIGNUM)) { + return rb_big_even_p(num); + } + else if (rb_funcall(num, '%', 1, INT2FIX(2)) == INT2FIX(0)) { return Qtrue; } return Qfalse; |