summaryrefslogtreecommitdiff
path: root/rational.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-15 09:25:13 (GMT)
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-15 09:25:13 (GMT)
commitcbe5f8820b71e0e9a214ae86e9264712e5580413 (patch)
treed4afebe00095341f51ea429f06ba294a501897f0 /rational.c
parent81af1bd9e8b8d84860cade1b5918b1c801b57845 (diff)
* 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
Diffstat (limited to 'rational.c')
-rw-r--r--rational.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/rational.c b/rational.c
index c8d5688..afa4bd4 100644
--- a/rational.c
+++ b/rational.c
@@ -1210,6 +1210,12 @@ f_round_common(int argc, VALUE *argv, VALUE self, VALUE (*func)(VALUE))
b = f_expt10(n);
s = f_mul(self, b);
+ if (k_float_p(s)) {
+ if (f_lt_p(n, ZERO))
+ return ZERO;
+ return self;
+ }
+
s = (*func)(s);
s = f_div(f_rational_new_bang1(CLASS_OF(self), s), b);