ruby-changes:44684
From: mrkn <ko1@a...>
Date: Sun, 13 Nov 2016 00:08:02 +0900 (JST)
Subject: [ruby-changes:44684] mrkn:r56756 (trunk): rational.c: define Rational#{negative?, positive?}
mrkn 2016-11-13 00:07:53 +0900 (Sun, 13 Nov 2016) New Revision: 56756 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56756 Log: rational.c: define Rational#{negative?,positive?} * rational.c (nurat_{negative,positive}_p): define Rational#negative? and Rational#positive?, respectively. Author: Tadashi Saito <tad.a.digger@g...> Modified files: trunk/rational.c Index: rational.c =================================================================== --- rational.c (revision 56755) +++ rational.c (revision 56756) @@ -1204,6 +1204,32 @@ nurat_true(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L1204 } #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) https://github.com/ruby/ruby/blob/trunk/rational.c#L2634 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/