mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
189ba5e0ac
commit
a36d273eab
1 changed files with 28 additions and 0 deletions
28
rational.c
28
rational.c
|
@ -1204,6 +1204,32 @@ nurat_true(VALUE self)
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
static VALUE
|
||||||
nurat_floor(VALUE self)
|
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, "rational?", nurat_true, 0);
|
||||||
rb_define_method(rb_cRational, "exact?", nurat_true, 0);
|
rb_define_method(rb_cRational, "exact?", nurat_true, 0);
|
||||||
#endif
|
#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, "floor", nurat_floor_n, -1);
|
||||||
rb_define_method(rb_cRational, "ceil", nurat_ceil_n, -1);
|
rb_define_method(rb_cRational, "ceil", nurat_ceil_n, -1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue