aboutsummaryrefslogtreecommitdiffstats
path: root/complex.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-27 02:55:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-27 02:55:03 +0000
commitbdebd65c50e96d9034e89d777a2213a99fd28d18 (patch)
tree8b373152fde59802bafa8653f5f6d9d33b944edf /complex.c
parent215b33e5bfeb264c3ee3f7d05bd0c742fc48ff65 (diff)
downloadruby-bdebd65c50e96d9034e89d777a2213a99fd28d18.tar.gz
complex.c: no overflow
* complex.c (rb_complex_infinite_p): get rid of overflow and unnecessary multiplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/complex.c b/complex.c
index 7cf1e7bf8a..5d84106441 100644
--- a/complex.c
+++ b/complex.c
@@ -253,6 +253,22 @@ f_finite_p(VALUE x)
return RTEST(rb_funcallv(x, id_finite_p, 0, 0));
}
+VALUE rb_flo_is_infinite_p(VALUE num);
+inline static VALUE
+f_infinite_p(VALUE x)
+{
+ if (RB_INTEGER_TYPE_P(x)) {
+ return Qnil;
+ }
+ else if (RB_FLOAT_TYPE_P(x)) {
+ return rb_flo_is_infinite_p(x);
+ }
+ else if (RB_TYPE_P(x, T_RATIONAL)) {
+ return Qnil;
+ }
+ return rb_funcallv(x, id_infinite_p, 0, 0);
+}
+
inline static int
f_kind_of_p(VALUE x, VALUE c)
{
@@ -1367,21 +1383,12 @@ rb_complex_finite_p(VALUE self)
static VALUE
rb_complex_infinite_p(VALUE self)
{
- VALUE magnitude = nucomp_abs(self);
+ get_dat1(self);
- if (FINITE_TYPE_P(magnitude)) {
- return Qnil;
- }
- if (RB_FLOAT_TYPE_P(magnitude)) {
- const double f = RFLOAT_VALUE(magnitude);
- if (isinf(f)) {
- return ONE;
- }
+ if (NIL_P(f_infinite_p(dat->real)) && NIL_P(f_infinite_p(dat->imag))) {
return Qnil;
}
- else {
- return rb_funcall(magnitude, id_infinite_p, 0);
- }
+ return ONE;
}
/* :nodoc: */