ruby-changes:19797
From: yugui <ko1@a...>
Date: Tue, 31 May 2011 09:13:25 +0900 (JST)
Subject: [ruby-changes:19797] yugui:r31842 (ruby_1_9_2): merges r31778 from trunk into ruby_1_9_2.
yugui 2011-05-31 09:13:13 +0900 (Tue, 31 May 2011) New Revision: 31842 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31842 Log: merges r31778 from trunk into ruby_1_9_2. -- * numeric.c (flo_round): fix for negative value. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/bignum.c branches/ruby_1_9_2/numeric.c branches/ruby_1_9_2/test/ruby/test_float.rb branches/ruby_1_9_2/version.h Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 31841) +++ ruby_1_9_2/ChangeLog (revision 31842) @@ -1,3 +1,7 @@ +Sun May 29 15:09:05 2011 Nobuyoshi Nakada <nobu@r...> + + * numeric.c (flo_round): fix for negative value. + Sat May 28 03:04:27 2011 NARUSE, Yui <naruse@r...> * io.c (fill_cbuf): return MORE_CHAR_SUSPENDED when cbuf is not empty. Index: ruby_1_9_2/numeric.c =================================================================== --- ruby_1_9_2/numeric.c (revision 31841) +++ ruby_1_9_2/numeric.c (revision 31842) @@ -97,6 +97,7 @@ } #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 @@ } 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; Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 31841) +++ ruby_1_9_2/version.h (revision 31842) @@ -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 Index: ruby_1_9_2/bignum.c =================================================================== --- ruby_1_9_2/bignum.c (revision 31841) +++ ruby_1_9_2/bignum.c (revision 31842) @@ -1608,7 +1608,7 @@ * Unary minus (returns an integer whose value is 0-big) */ -static VALUE +VALUE rb_big_uminus(VALUE x) { VALUE z = rb_big_clone(x); Index: ruby_1_9_2/test/ruby/test_float.rb =================================================================== --- ruby_1_9_2/test/ruby/test_float.rb (revision 31841) +++ ruby_1_9_2/test/ruby/test_float.rb (revision 31842) @@ -297,6 +297,7 @@ 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 = [ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/