diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 00:13:13 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 00:13:13 +0000 |
commit | d71702168ca57315179441bce49402295b28240c (patch) | |
tree | 941728365944fd8c2de3707253d4e598c576ce54 | |
parent | d500908417d88291a649a46de2766c3aa8dcf82d (diff) |
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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | bignum.c | 2 | ||||
-rw-r--r-- | numeric.c | 11 | ||||
-rw-r--r-- | test/ruby/test_float.rb | 1 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 16 insertions, 4 deletions
@@ -1,3 +1,7 @@ +Sun May 29 15:09:05 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * numeric.c (flo_round): fix for negative value. + Sat May 28 03:04:27 2011 NARUSE, Yui <naruse@ruby-lang.org> * io.c (fill_cbuf): return MORE_CHAR_SUSPENDED when cbuf is not empty. @@ -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); @@ -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 = [ @@ -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 |