diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-12 15:07:53 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-12 15:07:53 +0000 |
commit | a36d273eabbbac4ce883632bbcf877de7a062250 (patch) | |
tree | 120360ecc321788abde92edfaeb1ecd2d2e6c4d1 /rational.c | |
parent | 189ba5e0acd1269b535e63355e6eb06c6a25e3f7 (diff) |
rational.c: define Rational#{negative?,positive?}
* rational.c (nurat_{negative,positive}_p): define Rational#negative?
and Rational#positive?, respectively.
Author: Tadashi Saito <[email protected]>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/rational.c b/rational.c index 4545c2c3d5..4e0b9ed053 100644 --- a/rational.c +++ b/rational.c @@ -1204,6 +1204,32 @@ nurat_true(VALUE self) } #endif +/* + * call-seq: + * rat.positive? -> true or false + * + * Returns +true+ if +rat+ is greater than 0. + */ +static VALUE +nurat_positive_p(VALUE self) +{ + get_dat1(self); + return f_boolcast(INT_POSITIVE_P(dat->num)); +} + +/* + * call-seq: + * rat.negative? -> true or false + * + * Returns +true+ if +rat+ is less than 0. + */ +static VALUE +nurat_negative_p(VALUE self) +{ + get_dat1(self); + return f_boolcast(INT_NEGATIVE_P(dat->num)); +} + static VALUE nurat_floor(VALUE self) { @@ -2608,6 +2634,8 @@ Init_Rational(void) rb_define_method(rb_cRational, "rational?", nurat_true, 0); rb_define_method(rb_cRational, "exact?", nurat_true, 0); #endif + rb_define_method(rb_cRational, "positive?", nurat_positive_p, 0); + rb_define_method(rb_cRational, "negative?", nurat_negative_p, 0); rb_define_method(rb_cRational, "floor", nurat_floor_n, -1); rb_define_method(rb_cRational, "ceil", nurat_ceil_n, -1); |