summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-14 03:59:02 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-12-14 03:59:02 +0000
commit19f45f853c125ff744c53bd548f29f891c76c28b (patch)
treec32266f4b72a566688f4d26adabc6f2f3559457d /test/ruby
parent529ad093d42bd6ab802449747bf08a400563e12d (diff)
* 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
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_bignum.rb20
1 files changed, 20 insertions, 0 deletions
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