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

* rational.c (f_round_common): should check overflow.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2012-12-15 09:25:13 +00:00
parent 81af1bd9e8
commit cbe5f8820b
2 changed files with 10 additions and 0 deletions

View file

@ -1,3 +1,7 @@
Sat Dec 15 18:24:21 2012 Tadayoshi Funaba <tadf@dotrb.org>
* rational.c (f_round_common): should check overflow.
Sat Dec 15 18:00:00 2012 Tadayoshi Funaba <tadf@dotrb.org> Sat Dec 15 18:00:00 2012 Tadayoshi Funaba <tadf@dotrb.org>
* ratioanl.c (float_rationalize): reduced. * ratioanl.c (float_rationalize): reduced.

View file

@ -1210,6 +1210,12 @@ f_round_common(int argc, VALUE *argv, VALUE self, VALUE (*func)(VALUE))
b = f_expt10(n); b = f_expt10(n);
s = f_mul(self, b); s = f_mul(self, b);
if (k_float_p(s)) {
if (f_lt_p(n, ZERO))
return ZERO;
return self;
}
s = (*func)(s); s = (*func)(s);
s = f_div(f_rational_new_bang1(CLASS_OF(self), s), b); s = f_div(f_rational_new_bang1(CLASS_OF(self), s), b);