diff options
-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); |