From a2b83212d6cf280d13cc2e00d613fa5fe140a5c1 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 21 Jun 2008 07:21:10 +0000 Subject: [PATCH] * 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 --- ChangeLog | 4 ++++ numeric.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd6cdd003b..7facce3d8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jun 21 16:21:07 2008 Nobuyoshi Nakada + + * numeric.c (flo_round): get rid of overflow. + Sat Jun 21 15:57:15 2008 Nobuyoshi Nakada * lib/rdoc/parsers/parse_rb.rb (RDoc#collect_first_comment): skip diff --git a/numeric.c b/numeric.c index 318d6046f3..187044ee5e 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);