summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-21 07:21:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-21 07:21:10 +0000
commita2b83212d6cf280d13cc2e00d613fa5fe140a5c1 (patch)
tree1e09ba1bcb9c5a543f318adf5418c57338c8095a /numeric.c
parent47f5c15e8d6a6c78703b363e9fd351ac44b616e1 (diff)
* numeric.c (flo_round): get rid of overflow.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/numeric.c b/numeric.c
index 318d604..187044e 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1299,11 +1299,16 @@ flo_round(int argc, VALUE *argv, VALUE num)
while (--i >= 0)
f = f*10.0;
- if (ndigits < 0) number /= f;
- else number *= f;
- number = round(number);
- if (ndigits < 0) number *= f;
- else number /= f;
+ if (isinf(f)) {
+ if (ndigits < 0) number = 0;
+ }
+ else {
+ if (ndigits < 0) number /= f;
+ else number *= f;
+ number = round(number);
+ if (ndigits < 0) number *= f;
+ else number /= f;
+ }
if (ndigits > 0) return DOUBLE2NUM(number);