test/bigint.rb: add test for multi-precision integers.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-04-08 16:12:21 +09:00
parent f33537f4fd
commit 55b526167b
+23
View File
@@ -0,0 +1,23 @@
assert 'Bigint basic' do
n = 1<<65
assert_equal 36893488147419103232, n
assert_equal 36893488147419104229, n+997
assert_equal 36893488147419102235, n-997
assert_equal 36782807682976845922304, n*997
assert_equal 37004501652376231, n.div(997)
end
assert 'Bigint to_s' do
n = 1197857166996989179607278372168909873645893814254642585755536286462800958278984531968
assert_equal n, "11978_571669_96989179607278372168909873645893814254642585755536286462800958278984531968".to_i
assert_equal(-n, "-11978_571669_96989179607278372168909873645893814254642585755536286462800958278984531968".to_i)
n = 0x1197857166996989179607278372168909873645893814254642585755536286462800958278984531968
assert_equal n, "1197857166996989179607278372168909873645893814254642585755536286462800958278984531968".to_i(16)
end
assert 'Bigint pow' do
n = 18446744073709551616
assert_equal n, 2 ** 64
assert_equal n, 1 << 64
assert_equal 2, n >> 63
end