From 19f45f853c125ff744c53bd548f29f891c76c28b Mon Sep 17 00:00:00 2001 From: mame Date: Sun, 14 Dec 2008 03:59:02 +0000 Subject: * 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@20733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_bignum.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby/test_bignum.rb') diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index b60622fb17..29fda85572 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 -- cgit v1.2.3