From d71702168ca57315179441bce49402295b28240c Mon Sep 17 00:00:00 2001 From: yugui Date: Tue, 31 May 2011 00:13:13 +0000 Subject: merges r31778 from trunk into ruby_1_9_2. -- * numeric.c (flo_round): fix for negative value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ bignum.c | 2 +- numeric.c | 11 +++++++++-- test/ruby/test_float.rb | 1 + version.h | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4ea439dac..d37a774fc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun May 29 15:09:05 2011 Nobuyoshi Nakada + + * numeric.c (flo_round): fix for negative value. + Sat May 28 03:04:27 2011 NARUSE, Yui * io.c (fill_cbuf): return MORE_CHAR_SUSPENDED when cbuf is not empty. diff --git a/bignum.c b/bignum.c index 9181c9dd1c..fdbd300660 100644 --- a/bignum.c +++ b/bignum.c @@ -1608,7 +1608,7 @@ rb_big_eql(VALUE x, VALUE y) * Unary minus (returns an integer whose value is 0-big) */ -static VALUE +VALUE rb_big_uminus(VALUE x) { VALUE z = rb_big_clone(x); diff --git a/numeric.c b/numeric.c index c67043e25e..4a3efac844 100644 --- a/numeric.c +++ b/numeric.c @@ -97,6 +97,7 @@ round(double x) } #endif +static VALUE fix_uminus(VALUE num); static VALUE fix_mul(VALUE x, VALUE y); static VALUE int_pow(long x, unsigned long y); @@ -1454,10 +1455,16 @@ flo_round(int argc, VALUE *argv, VALUE num) } else { if (ndigits < 0) { - if (fabs(number) < f) return INT2FIX(0); + double absnum = fabs(number); + if (absnum < f) return INT2FIX(0); if (!FIXABLE(number)) { VALUE f10 = int_pow(10, -ndigits); - num = rb_big_idiv(rb_dbl2big(number), f10); + VALUE n10 = f10; + if (number < 0) { + extern VALUE rb_big_uminus(VALUE x); + f10 = FIXNUM_P(f10) ? fix_uminus(f10) : rb_big_uminus(f10); + } + num = rb_big_idiv(rb_dbl2big(absnum), n10); return FIXNUM_P(num) ? fix_mul(num, f10) : rb_big_mul(num, f10); } number /= f; diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index ab5f9bdc07..77645a91fc 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -297,6 +297,7 @@ class TestFloat < Test::Unit::TestCase assert_equal(11100.0, 11111.1.round(-2)) assert_equal(10**300, 1.1e300.round(-300)) + assert_equal(-10**300, -1.1e300.round(-300)) end VS = [ diff --git a/version.h b/version.h index 32378f2645..821d93023e 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 259 +#define RUBY_PATCHLEVEL 260 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 -- cgit v1.2.3