Skip to content

Commit

Permalink
test/bigint.rb: add test for multi-precision integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 9, 2022
1 parent f33537f commit 55b5261
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mrbgems/mruby-bigint/test/bigint.rb
@@ -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

0 comments on commit 55b5261

Please sign in to comment.