diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-14 03:59:02 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-14 03:59:02 +0000 |
commit | f24d5aba4aea1a3c1f6f600bd745a277f12f1b78 (patch) | |
tree | c32266f4b72a566688f4d26adabc6f2f3559457d /test | |
parent | c1f15cf03ff76949bc199a9e0b8cac9115551a72 (diff) | |
download | ruby-f24d5aba4aea1a3c1f6f600bd745a277f12f1b78.tar.gz ruby-f24d5aba4aea1a3c1f6f600bd745a277f12f1b78.tar.xz ruby-f24d5aba4aea1a3c1f6f600bd745a277f12f1b78.zip |
* bignum.c (rb_big_mul): faster multiplication by Karatsuba method and
twice faster square than normal multiplication.
* random.c (rb_rand_internal): used by Bignum#*.
* test/ruby/test_bignum.rb: add some tests for above.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@20733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_bignum.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index b60622fb1..29fda8557 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -200,11 +200,24 @@ class TestBignum < Test::Unit::TestCase def test_sub assert_equal(-T31, T32 - (T32 + T31)) + x = 2**100 + assert_equal(1, (x+2) - (x+1)) + assert_equal(-1, (x+1) - (x+2)) + assert_equal(0, (2**100) - (2.0**100)) + o = Object.new + def o.coerce(x); [2**100+2, x]; end + assert_equal(1, (2**100+1) - o) end def test_plus assert_equal(T32.to_f, T32P + 1.0) assert_raise(TypeError) { T32 + "foo" } + assert_equal(1267651809154049016125877911552, (2**100) + (2**80)) + assert_equal(1267651809154049016125877911552, (2**80) + (2**100)) + assert_equal(2**101, (2**100) + (2.0**100)) + o = Object.new + def o.coerce(x); [2**80, x]; end + assert_equal(1267651809154049016125877911552, (2**100) + o) end def test_minus @@ -215,6 +228,13 @@ class TestBignum < Test::Unit::TestCase def test_mul assert_equal(T32.to_f, T32 * 1.0) assert_raise(TypeError) { T32 * "foo" } + o = Object.new + def o.coerce(x); [2**100, x]; end + assert_equal(2**180, (2**80) * o) + end + + def test_mul_balance + assert_equal(3**7000, (3**5000) * (3**2000)) end def test_divrem |