ruby-changes:67562
From: Nobuyoshi <ko1@a...>
Date: Thu, 2 Sep 2021 23:11:45 +0900 (JST)
Subject: [ruby-changes:67562] a95262356e (master): Extract always_finite_type_p and handle flonum cases
https://git.ruby-lang.org/ruby.git/commit/?id=a95262356e From a95262356ef5b975f4b4b88db97dca93f451f74b Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 2 Sep 2021 21:42:47 +0900 Subject: Extract always_finite_type_p and handle flonum cases --- complex.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/complex.c b/complex.c index 647fff9..0c50196 100644 --- a/complex.c +++ b/complex.c @@ -334,15 +334,23 @@ f_zero_p(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L334 #define f_nonzero_p(x) (!f_zero_p(x)) +static inline bool +always_finite_type_p(VALUE x) +{ + if (FIXNUM_P(x)) return true; + if (FLONUM_P(x)) return true; /* Infinity can't be a flonum */ + return (RB_INTEGER_TYPE_P(x) || RB_TYPE_P(x, T_RATIONAL)); +} + VALUE rb_flo_is_finite_p(VALUE num); inline static int f_finite_p(VALUE x) { - if (RB_INTEGER_TYPE_P(x) || RB_TYPE_P(x, T_RATIONAL)) { + if (always_finite_type_p(x)) { return TRUE; } else if (RB_FLOAT_TYPE_P(x)) { - return (int)rb_flo_is_finite_p(x); + return isfinite(RFLOAT_VALUE(x)); } return RTEST(rb_funcallv(x, id_finite_p, 0, 0)); } @@ -351,11 +359,11 @@ VALUE rb_flo_is_infinite_p(VALUE num); https://github.com/ruby/ruby/blob/trunk/complex.c#L359 inline static int f_infinite_p(VALUE x) { - if (RB_INTEGER_TYPE_P(x) || RB_TYPE_P(x, T_RATIONAL)) { + if (always_finite_type_p(x)) { return FALSE; } else if (RB_FLOAT_TYPE_P(x)) { - return RTEST(rb_flo_is_infinite_p(x)); + return isinf(RFLOAT_VALUE(x)); } return RTEST(rb_funcallv(x, id_infinite_p, 0, 0)); } -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/