summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-16 14:41:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-16 14:41:11 +0000
commit1f693690c7c4aef9c23ecb441af400c2427c9dbf (patch)
tree46fcb91af5603a022818ef3fa4425649fe026179
parentf7f546fa935364db5e90b2af6f89b8d8fff2e9a6 (diff)
downloadruby-1f693690c7c4aef9c23ecb441af400c2427c9dbf.tar.gz
ruby-1f693690c7c4aef9c23ecb441af400c2427c9dbf.tar.xz
ruby-1f693690c7c4aef9c23ecb441af400c2427c9dbf.zip
* bignum.c (rb_big_odd_p): new method added. a patch from Tadashi
Saito <shiba AT mail2.accsnet.ne.jp>. [ruby-dev:32305] * bignum.c (rb_big_even_p): ditto. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--bignum.c34
2 files changed, 41 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 9970b5dea..5d722bd9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Nov 16 23:31:18 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (rb_big_odd_p): new method added. a patch from Tadashi
+ Saito <shiba AT mail2.accsnet.ne.jp>. [ruby-dev:32305]
+
+ * bignum.c (rb_big_even_p): ditto.
+
Fri Nov 16 17:41:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv/iconv.c (Document-class): moved the simplest example to
diff --git a/bignum.c b/bignum.c
index 138922c41..71e0fb8da 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2432,6 +2432,38 @@ rb_big_size(VALUE big)
}
/*
+ * call-seq:
+ * big.odd? -> true or false
+ *
+ * Returns <code>true</code> if <i>big</i> is an odd number.
+ */
+
+static VALUE
+rb_big_odd_p(VALUE num)
+{
+ if (BDIGITS(num)[0] & 1) {
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
+/*
+ * call-seq:
+ * big.even? -> true or false
+ *
+ * Returns <code>true</code> if <i>big</i> is an even number.
+ */
+
+static VALUE
+rb_big_even_p(VALUE num)
+{
+ if (BDIGITS(num)[0] & 1) {
+ return Qfalse;
+ }
+ return Qtrue;
+}
+
+/*
* Bignum objects hold integers outside the range of
* Fixnum. Bignum objects are created
* automatically when integer calculations would otherwise overflow a
@@ -2484,6 +2516,8 @@ Init_Bignum(void)
rb_define_method(rb_cBignum, "to_f", rb_big_to_f, 0);
rb_define_method(rb_cBignum, "abs", rb_big_abs, 0);
rb_define_method(rb_cBignum, "size", rb_big_size, 0);
+ rb_define_method(rb_cBignum, "odd?", rb_big_odd_p, 0);
+ rb_define_method(rb_cBignum, "even?", rb_big_even_p, 0);
power_cache_init();
}