From c7260f9d7cab69fc1ce636795a2097a4ab15f138 Mon Sep 17 00:00:00 2001 From: mrkn Date: Sat, 12 Nov 2016 15:07:53 +0000 Subject: rational.c: define Rational#{negative?,positive?} * rational.c (nurat_{negative,positive}_p): define Rational#negative? and Rational#positive?, respectively. Author: Tadashi Saito git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- rational.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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); -- cgit v1.2.3