summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorS.H <gamelinks007@gmail.com>2021-09-15 08:11:05 +0900
committerGitHub <noreply@github.com>2021-09-15 08:11:05 +0900
commitb8c3a84bddac7366c4e391234b2535253869e885 (patch)
tree872dfa2014b75fc4c5dadb060900afa118cded71 /numeric.c
parent89242279e61b023a81c58065c62a82de8829d0b3 (diff)
Refactor and Using RBOOL macro
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4837 Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/numeric.c b/numeric.c
index 39c2bd7b82..3b481b3869 100644
--- a/numeric.c
+++ b/numeric.c
@@ -755,18 +755,10 @@ static VALUE
int_zero_p(VALUE num)
{
if (FIXNUM_P(num)) {
- if (FIXNUM_ZERO_P(num)) {
- return Qtrue;
- }
- }
- else {
- assert(RB_BIGNUM_TYPE_P(num));
- if (rb_bigzero_p(num)) {
- /* this should not happen usually */
- return Qtrue;
- }
+ return RBOOL(FIXNUM_ZERO_P(num));
}
- return Qfalse;
+ assert(RB_BIGNUM_TYPE_P(num));
+ return RBOOL(rb_bigzero_p(num));
}
VALUE
@@ -1368,7 +1360,7 @@ rb_float_equal(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
- return (a == b)?Qtrue:Qfalse;
+ return RBOOL(a == b);
}
#define flo_eq rb_float_equal
@@ -1491,7 +1483,7 @@ rb_float_gt(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
- return (a > b)?Qtrue:Qfalse;
+ return RBOOL(a > b);
}
/*
@@ -1528,7 +1520,7 @@ flo_ge(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
- return (a >= b)?Qtrue:Qfalse;
+ return RBOOL(a >= b);
}
/*
@@ -1565,7 +1557,7 @@ flo_lt(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
- return (a < b)?Qtrue:Qfalse;
+ return RBOOL(a < b);
}
/*
@@ -1602,7 +1594,7 @@ flo_le(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
- return (a <= b)?Qtrue:Qfalse;
+ return RBOOL(a <= b);
}
/*
@@ -1627,8 +1619,7 @@ rb_float_eql(VALUE x, VALUE y)
#if MSC_VERSION_BEFORE(1300)
if (isnan(a) || isnan(b)) return Qfalse;
#endif
- if (a == b)
- return Qtrue;
+ return RBOOL(a == b);
}
return Qfalse;
}
@@ -4094,8 +4085,7 @@ static VALUE
fix_gt(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
- if (FIX2LONG(x) > FIX2LONG(y)) return Qtrue;
- return Qfalse;
+ return RBOOL(FIX2LONG(x) > FIX2LONG(y));
}
else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) == INT2FIX(-1));
@@ -4133,8 +4123,7 @@ static VALUE
fix_ge(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
- if (FIX2LONG(x) >= FIX2LONG(y)) return Qtrue;
- return Qfalse;
+ return RBOOL(FIX2LONG(x) >= FIX2LONG(y));
}
else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) != INT2FIX(+1));
@@ -4172,8 +4161,7 @@ static VALUE
fix_lt(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
- if (FIX2LONG(x) < FIX2LONG(y)) return Qtrue;
- return Qfalse;
+ return RBOOL(FIX2LONG(x) < FIX2LONG(y));
}
else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) == INT2FIX(+1));
@@ -4211,8 +4199,7 @@ static VALUE
fix_le(VALUE x, VALUE y)
{
if (FIXNUM_P(y)) {
- if (FIX2LONG(x) <= FIX2LONG(y)) return Qtrue;
- return Qfalse;
+ return RBOOL(FIX2LONG(x) <= FIX2LONG(y));
}
else if (RB_BIGNUM_TYPE_P(y)) {
return RBOOL(rb_big_cmp(y, x) != INT2FIX(-1));