[前][次][番号順一覧][スレッド一覧]

ruby-changes:67555

From: Nobuyoshi <ko1@a...>
Date: Thu, 2 Sep 2021 17:49:15 +0900 (JST)
Subject: [ruby-changes:67555] 137fde717b (master): Make internal predicate functions to return simple boolean

https://git.ruby-lang.org/ruby.git/commit/?id=137fde717b

From 137fde717bfa4d1a116bf1d56c288a1f3016126c Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 2 Sep 2021 17:12:17 +0900
Subject: Make internal predicate functions to return simple boolean

---
 complex.c  | 15 ++++++---------
 rational.c |  2 +-
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/complex.c b/complex.c
index 3fbda12..647fff9 100644
--- a/complex.c
+++ b/complex.c
@@ -338,29 +338,26 @@ VALUE rb_flo_is_finite_p(VALUE num); https://github.com/ruby/ruby/blob/trunk/complex.c#L338
 inline static int
 f_finite_p(VALUE x)
 {
-    if (RB_INTEGER_TYPE_P(x)) {
+    if (RB_INTEGER_TYPE_P(x) || RB_TYPE_P(x, T_RATIONAL)) {
         return TRUE;
     }
     else if (RB_FLOAT_TYPE_P(x)) {
 	return (int)rb_flo_is_finite_p(x);
     }
-    else if (RB_TYPE_P(x, T_RATIONAL)) {
-	return TRUE;
-    }
     return RTEST(rb_funcallv(x, id_finite_p, 0, 0));
 }
 
 VALUE rb_flo_is_infinite_p(VALUE num);
-inline static VALUE
+inline static int
 f_infinite_p(VALUE x)
 {
     if (RB_INTEGER_TYPE_P(x) || RB_TYPE_P(x, T_RATIONAL)) {
-        return Qnil;
+        return FALSE;
     }
     else if (RB_FLOAT_TYPE_P(x)) {
-	return rb_flo_is_infinite_p(x);
+	return RTEST(rb_flo_is_infinite_p(x));
     }
-    return rb_funcallv(x, id_infinite_p, 0, 0);
+    return RTEST(rb_funcallv(x, id_infinite_p, 0, 0));
 }
 
 inline static int
@@ -1469,7 +1466,7 @@ rb_complex_infinite_p(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1466
 {
     get_dat1(self);
 
-    if (NIL_P(f_infinite_p(dat->real)) && NIL_P(f_infinite_p(dat->imag))) {
+    if (!f_infinite_p(dat->real) && !f_infinite_p(dat->imag)) {
 	return Qnil;
     }
     return ONE;
diff --git a/rational.c b/rational.c
index 8fae9c7..313dd08 100644
--- a/rational.c
+++ b/rational.c
@@ -128,7 +128,7 @@ f_abs(VALUE x) https://github.com/ruby/ruby/blob/trunk/rational.c#L128
 }
 
 
-inline static VALUE
+inline static int
 f_integer_p(VALUE x)
 {
     return RB_INTEGER_TYPE_P(x);
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]