mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
test/bigint.rb: add test for multi-precision integers.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user