summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-02 21:42:47 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-02 23:11:33 +0900
commita95262356ef5b975f4b4b88db97dca93f451f74b (patch)
tree27724b754ed1ebbeabcf94564e8c1797c98e7f95 /complex.c
parent682f58a93354fe4bf5a8ac83be9b1e553d41afcd (diff)
Extract always_finite_type_p and handle flonum cases
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4801
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/complex.c b/complex.c
index 647fff9d1d..0c50196627 100644
--- a/complex.c
+++ b/complex.c
@@ -334,15 +334,23 @@ f_zero_p(VALUE x)
#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);
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));
}