ruby-changes:53509
From: shyouhei <ko1@a...>
Date: Wed, 14 Nov 2018 18:53:18 +0900 (JST)
Subject: [ruby-changes:53509] shyouhei:r65725 (trunk): numeric.c: avoid division by zero
shyouhei 2018-11-14 18:53:11 +0900 (Wed, 14 Nov 2018) New Revision: 65725 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65725 Log: numeric.c: avoid division by zero same as r65642. Modified files: trunk/rational.c Index: rational.c =================================================================== --- rational.c (revision 65724) +++ rational.c (revision 65725) @@ -929,8 +929,11 @@ nurat_div(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/rational.c#L929 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) https://github.com/ruby/ruby/blob/trunk/rational.c#L971 { 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/