Skip to content

Instantly share code, notes, and snippets.

@peschwa
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peschwa/150ce4c48f64247c6b7c to your computer and use it in GitHub Desktop.
Save peschwa/150ce4c48f64247c6b7c to your computer and use it in GitHub Desktop.
$ NODE_PATH=/home/psch/rakudo/nqp-js/node_modules/nqp-runtime-node/node_modules/ node
> var bigint = require('bigint')
undefined
> var b = bigint(-123).pow(42)
undefined
> console.log(b)
<BigInt 5970554685064519004265641008828923248442340700473500698131071806779372733915289638628729>
undefined
> var zero = bigint(0).pow(b)
undefined
> console.log(zero)
<BigInt 1>
undefined
# latest means this one: http://pastie.org/9430174#8-9
not ok 1 - pow 0 ** large_number
# $c = -123
# $big = 5970554685064519004265641008828923248442340700473500698131071806779372733915289638628729
# 0 = 0
# 0 ** $big = 1
nqp-js$ prove -e './nqp-js' t/nqp/60-bigint.t -v
t/nqp/60-bigint.t ..
1..47
ok 1 - can round-trip negative number (string)
ok 2 - can round-trip negative number (string) by boxing
ok 3 - can round-trip negative number by unboxing
ok 4 - nqp::iseq_I can return false
ok 5 - nqp::iseq_I can return true
ok 6 - multiplication
ok 7 - addition
ok 8 - subtraction
ok 9 - division
ok 10 - bitshift left
ok 11 - original not modified by bitshift left
ok 12 - bitshift right
ok 13 - bit and
ok 14 - bit or
ok 15 - bit xor
ok 16 - bit negation
ok 17 - Bit ops (RT 109740)
ok 18 - can box to a complex type with a P6bigint target
ok 19 - can get a bigint from a string with boxing type
ok 20 - addition works on boxing type
ok 21 - pow (int, positive)
not ok 22 - pow 0 ** large_number
ok 23 - pow 1 ** large_number
ok 24 - 2**100 to float
ok 25 - (-2)**101 to float
ok 26 - 123456789 * (-2)**101 to float
ok 27 - bigint -> float, 1e16
ok 28 - to_num and from_num round-trip
ok 29 - to_num and from_num round-trip on small floats
ok 30 - to_num and from_num round-trip on medium sized floats
ok 31 - to_num and from_num round-trip (negative number)
ok 32 - base_I with base 10
ok 33 - base_I with base 16
ok 34 - nqp::expmod_I
ok 35 - div_In santiy
ok 36 - div_In with big numbers
ok 37 - nqp::rand_I
ok 38 - is -4 prime
ok 39 - is 0 prime
ok 40 - is 1 prime
ok 41 - is 2 prime
ok 42 - is 4 prime
ok 43 - is 17 prime
ok 44 - nqp::gcd_I
ok 45 - nqp::lcm_I
ok 46 - bool_I(42)
ok 47 - bool_I(0)
Failed 1/47 subtests
Test Summary Report
-------------------
t/nqp/60-bigint.t (Wstat: 0 Tests: 47 Failed: 1)
Failed test: 22
Files=1, Tests=47, 1 wallclock secs ( 0.03 usr 0.00 sys + 1.42 cusr 0.26 csys = 1.71 CPU)
Result: FAIL
# this program
my $knowhow := nqp::knowhow();
my $bi_type := $knowhow.new_type(:name('TestBigInt'), :repr('P6bigint'));
$bi_type.HOW.compose($bi_type);
sub box($x) { nqp::box_i($x, $bi_type) }
my $c := box(-123);
my $big := nqp::pow_I($c, box(42), $bi_type, $bi_type);
while nqp::tonum_I($big) > nqp::tonum_I(box(0)) {
nqp::say("0 ** " ~ nqp::unbox_i($big) ~ ": " ~ nqp::unbox_i(nqp::pow_I(box(0), $big, $bi_type, $bi_type)));
$big := nqp::div_I($big, box(10), $big);
}
# produces this result
0 ** 5.970554685064519e+87: 1
0 ** 5.97055468506452e+86: 1
0 ** 5.970554685064519e+85: 1
0 ** 5.970554685064519e+84: 1
0 ** 5.97055468506452e+83: 1
0 ** 5.970554685064519e+82: 1
0 ** 5.970554685064519e+81: 1
0 ** 5.970554685064519e+80: 1
0 ** 5.970554685064519e+79: 1
0 ** 5.970554685064519e+78: 1
0 ** 5.970554685064519e+77: 1
0 ** 5.970554685064519e+76: 1
0 ** 5.970554685064519e+75: 1
0 ** 5.970554685064519e+74: 1
0 ** 5.97055468506452e+73: 1
0 ** 5.970554685064519e+72: 1
0 ** 5.970554685064519e+71: 1
0 ** 5.97055468506452e+70: 1
0 ** 5.970554685064519e+69: 1
0 ** 5.970554685064519e+68: 1
0 ** 5.970554685064519e+67: 1
0 ** 5.970554685064519e+66: 1
0 ** 5.970554685064519e+65: 1
0 ** 5.970554685064519e+64: 1
0 ** 5.970554685064519e+63: 1
0 ** 5.970554685064519e+62: 1
0 ** 5.970554685064519e+61: 1
0 ** 5.970554685064519e+60: 1
0 ** 5.970554685064519e+59: 1
0 ** 5.970554685064518e+58: 1
0 ** 5.970554685064519e+57: 1
0 ** 5.970554685064519e+56: 1
0 ** 5.970554685064519e+55: 1
0 ** 5.970554685064519e+54: 1
0 ** 5.970554685064519e+53: 1
0 ** 5.970554685064519e+52: 1
0 ** 5.970554685064519e+53: 1
0 ** 5.970554685064519e+52: 1
0 ** 5.970554685064519e+51: 1
0 ** 5.970554685064519e+50: 1
0 ** 5.970554685064519e+49: 1
0 ** 5.970554685064519e+48: 1
0 ** 5.970554685064519e+47: 1
0 ** 5.970554685064519e+46: 1
0 ** 5.97055468506452e+45: 1
0 ** 5.970554685064519e+44: 1
0 ** 5.970554685064519e+43: 1
0 ** 5.970554685064519e+42: 1
0 ** 5.970554685064519e+41: 1
0 ** 5.970554685064519e+40: 1
0 ** 5.970554685064519e+39: 1
0 ** 5.970554685064519e+38: 1
0 ** 5.970554685064519e+37: 1
0 ** 5.970554685064518e+36: 1
0 ** 5.970554685064519e+35: 1
0 ** 5.970554685064519e+34: 1
0 ** 5.97055468506452e+33: 1
0 ** 5.970554685064519e+32: 1
0 ** 5.970554685064519e+31: 1
0 ** 5.970554685064519e+30: 1
0 ** 5.970554685064519e+29: 1
0 ** 5.970554685064519e+28: 1
0 ** 5.970554685064519e+27: 1
0 ** 5.970554685064519e+26: 1
0 ** 5.970554685064519e+25: 1
0 ** 5.970554685064519e+24: 1
0 ** 5.970554685064519e+23: 1
0 ** 5.970554685064519e+22: 1
0 ** 5.970554685064519e+21: 1
0 ** 597055468506452000000: 1
0 ** 59705546850645190000: 1
0 ** 5970554685064519000: 0
0 ** 59705546850645190000: 1
0 ** 5970554685064519000: 0
0 ** 597055468506451800: 0
0 ** 59705546850645190: 0
0 ** 5970554685064519: 0
0 ** 597055468506451: 0
0 ** 59705546850645: 0
0 ** 5970554685064: 0
0 ** 597055468506: 0
0 ** 59705546850: 0
0 ** 5970554685: 0
0 ** 597055468: 0
0 ** 59705546: 0
0 ** 5970554: 0
0 ** 597055: 0
0 ** 59705: 0
0 ** 5970: 0
0 ** 597: 0
0 ** 59: 0
0 ** 5: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment