From 620f456dcc232d70a016ccb9672dcc901d0bbaea Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 28 Oct 2016 06:19:00 +0000 Subject: complex.c: FINITE_TYPE_P * complex.c (FINITE_TYPE_P): extract predicate. * complex.c (rb_complex_finite_p, rb_complex_infinite_p): use dedicated predicates instead of switch by TYPE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'complex.c') diff --git a/complex.c b/complex.c index 2544f3d9f7..7699463e28 100644 --- a/complex.c +++ b/complex.c @@ -1331,6 +1331,8 @@ nucomp_inspect(VALUE self) return s; } +#define FINITE_TYPE_P(v) (RB_INTEGER_TYPE_P(v) || RB_TYPE_P(v, T_RATIONAL)) + /* * call-seq: * cmp.finite? -> true or false @@ -1342,17 +1344,15 @@ static VALUE rb_complex_finite_p(VALUE self) { VALUE magnitude = nucomp_abs(self); - double f; - switch (TYPE(magnitude)) { - case T_FIXNUM: case T_BIGNUM: case T_RATIONAL: + if (FINITE_TYPE_P(magnitude)) { return Qtrue; - - case T_FLOAT: - f = RFLOAT_VALUE(magnitude); + } + else if (RB_FLOAT_TYPE_P(magnitude)) { + const double f = RFLOAT_VALUE(magnitude); return isinf(f) ? Qfalse : Qtrue; - - default: + } + else { return rb_funcall(magnitude, rb_intern("finite?"), 0); } } @@ -1375,20 +1375,18 @@ static VALUE rb_complex_infinite_p(VALUE self) { VALUE magnitude = nucomp_abs(self); - double f; - switch (TYPE(magnitude)) { - case T_FIXNUM: case T_BIGNUM: case T_RATIONAL: + if (FINITE_TYPE_P(magnitude)) { return Qnil; - - case T_FLOAT: - f = RFLOAT_VALUE(magnitude); + } + if (RB_FLOAT_TYPE_P(magnitude)) { + const double f = RFLOAT_VALUE(magnitude); if (isinf(f)) { return INT2FIX(f < 0 ? -1 : 1); } return Qnil; - - default: + } + else { return rb_funcall(magnitude, rb_intern("infinite?"), 0); } } -- cgit v1.2.3