1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* rational (nurat_marshal_load): checks the given

denominator. [ruby-dev:34536]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-04-28 11:28:55 +00:00
parent cb2bfadd2d
commit 420a5c994c
2 changed files with 19 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Mon Apr 28 20:24:27 2008 Tadayoshi Funaba <tadf@dotrb.org>
* rational (nurat_marshal_load): checks the given
denominator. [ruby-dev:34536]
Mon Apr 28 14:21:18 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/ruby.h (POSFIXABLE): use FIXNUM_MAX+1 instead of

View file

@ -407,9 +407,14 @@ nurat_s_new_bang(int argc, VALUE *argv, VALUE klass)
if (!k_integer_p(den))
den = f_to_i(den);
if (f_negative_p(den)) {
switch (FIX2INT(f_cmp(den, ZERO))) {
case -1:
num = f_negate(num);
den = f_negate(den);
break;
case 0:
rb_raise(rb_eZeroDivError, "devided by zero");
break;
}
break;
}
@ -452,10 +457,8 @@ nurat_s_canonicalize_internal(VALUE klass, VALUE num, VALUE den)
switch (FIX2INT(f_cmp(den, ZERO))) {
case -1:
if (f_negative_p(den)) {
num = f_negate(num);
den = f_negate(den);
}
num = f_negate(num);
den = f_negate(den);
break;
case 0:
rb_raise(rb_eZeroDivError, "devided by zero");
@ -477,10 +480,8 @@ nurat_s_canonicalize_internal_no_reduce(VALUE klass, VALUE num, VALUE den)
{
switch (FIX2INT(f_cmp(den, ZERO))) {
case -1:
if (f_negative_p(den)) {
num = f_negate(num);
den = f_negate(den);
}
num = f_negate(num);
den = f_negate(den);
break;
case 0:
rb_raise(rb_eZeroDivError, "devided by zero");
@ -1190,6 +1191,10 @@ nurat_marshal_load(VALUE self, VALUE a)
get_dat1(self);
dat->num = RARRAY_PTR(a)[0];
dat->den = RARRAY_PTR(a)[1];
if (f_zero_p(dat->den))
rb_raise(rb_eZeroDivError, "devided by zero");
return self;
}