diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-14 09:53:11 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-14 09:53:11 +0000 |
commit | a6e887153ea2d97adef5b2ef9ad6b0f5414ed0f7 (patch) | |
tree | e851d87c22b72cdbf1ad139b9222bd7404d62c6c | |
parent | ed42b0102d823e7897f2b63d104cb818af09d47d (diff) | |
download | ruby-a6e887153ea2d97adef5b2ef9ad6b0f5414ed0f7.tar.gz |
numeric.c: avoid division by zero
same as r65642.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | rational.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/rational.c b/rational.c index 7f3b9b08c7..a3a54d4eff 100644 --- a/rational.c +++ b/rational.c @@ -929,8 +929,11 @@ nurat_div(VALUE self, VALUE other) other, ONE, '/'); } } - else if (RB_FLOAT_TYPE_P(other)) - return DBL2NUM(nurat_to_double(self) / RFLOAT_VALUE(other)); + else if (RB_FLOAT_TYPE_P(other)) { + double d = nurat_to_double(self); + VALUE v = rb_float_new(d); + return rb_flo_div_flo(v, other); + } else if (RB_TYPE_P(other, T_RATIONAL)) { if (f_zero_p(other)) rb_num_zerodiv(); @@ -968,7 +971,7 @@ nurat_fdiv(VALUE self, VALUE other) { VALUE div; if (f_zero_p(other)) - return DBL2NUM(nurat_to_double(self) / 0.0); + return nurat_div(self, rb_float_new(0.0)); if (FIXNUM_P(other) && other == LONG2FIX(1)) return nurat_to_f(self); div = nurat_div(self, other); |