X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/b282a5527464951004e354d07709b58fcb3bdad0..7596a890808c68b396a85f42b3695b1e97cbe208:/lib/Math/BigInt/t/bigintpm.inc diff --git a/lib/Math/BigInt/t/bigintpm.inc b/lib/Math/BigInt/t/bigintpm.inc index 3cbb993..e842a2a 100644 --- a/lib/Math/BigInt/t/bigintpm.inc +++ b/lib/Math/BigInt/t/bigintpm.inc @@ -476,6 +476,14 @@ $x = $class->new('1_000_000_000_000'); ($x,$y) = $x->length(); ok ($x,13); ok ($y,0); +# test <<=, >>= +$x = $class->new('2'); +my $y = $class->new('18'); +ok ($x <<= $y, 2 << 18); +ok ($x, 2 << 18); +ok ($x >>= $y, 2); +ok ($x, 2); + # I am afraid the following is not yet possible due to slowness # Also, testing for 2 meg output is a bit hard ;) #$x = $class->new(2); $x **= 6972593; $x--; @@ -624,6 +632,28 @@ ok ($class->new(1)->is_one(),1); ok ($class->new(-1)->is_one(),0); ############################################################################### +# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x + +$x = $class->new(3); $x -= $x; ok ($x, 0); +$x = $class->new(-3); $x -= $x; ok ($x, 0); +$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1); +$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1); +$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1); + +$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1); +$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1); +$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1); +$x = $class->new(3); $x += $x; ok ($x, 6); +$x = $class->new(-3); $x += $x; ok ($x, -6); + +$x = $class->new(3); $x *= $x; ok ($x, 9); +$x = $class->new(-3); $x *= $x; ok ($x, 9); +$x = $class->new(3); $x /= $x; ok ($x, 1); +$x = $class->new(-3); $x /= $x; ok ($x, 1); +$x = $class->new(3); $x %= $x; ok ($x, 0); +$x = $class->new(-3); $x %= $x; ok ($x, 0); + +############################################################################### # all tests done 1; @@ -748,7 +778,7 @@ inf:inf:NaN -inf:1 NaNneg:0 &is_positive -0:1 +0:0 -1:0 1:1 +inf:1 @@ -810,6 +840,10 @@ acmpNaN:acmpNaN: -inf:123:1 +inf:-123:1 -inf:-123:1 +123:-inf:-1 +-123:inf:-1 +-123:-inf:-1 +123:inf:-1 # return undef +inf:NaN: NaN:inf: @@ -910,6 +944,8 @@ NaN:-inf: 0x200000001:8589934593 0x400000001:17179869185 0x800000001:34359738369 +# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex() +0x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691 # inf input inf:inf +inf:inf @@ -973,6 +1009,32 @@ E23:NaN 012345678912:12345678912 0123456789123:123456789123 01234567891234:1234567891234 +# some inputs that result in zero +0e0:0 ++0e0:0 ++0e+0:0 +-0e+0:0 +0e-0:0 +-0e-0:0 ++0e-0:0 +000:0 +00e2:0 +00e02:0 +000e002:0 +000e1230:0 +00e-3:0 +00e+3:0 +00e-03:0 +00e+03:0 +-000:0 +-00e2:0 +-00e02:0 +-000e002:0 +-000e1230:0 +-00e-3:0 +-00e+3:0 +-00e-03:0 +-00e+03:0 # normal input 0:0 +0:0 @@ -1435,6 +1497,29 @@ inf:0:inf,inf 1234567890999999999:9876543210:124999998,9503086419 1234567890000000000:9876543210:124999998,8503086420 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451 +# bug in v1.76 +1267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375 +# excercise shortcut for numbers of the same length in div +999999999999999999999999999999999:999999999999999999999999999999999:1,0 +999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111 +999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222 +999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333 +999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444 +999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111 +999999999999999999999999999999999:333333333333333333333333333333333:3,0 +999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111 +999999999999999999999999999999999:111111111111111111111111111111111:9,0 +9999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0 +9999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999 +9999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999 +9999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999 +9999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999 +9999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999 +9999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999 +9999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999 +9999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999 +9999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999 +9999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999 &bdiv abc:abc:NaN abc:1:NaN @@ -1529,6 +1614,29 @@ inf:0:inf 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997 +# excercise shortcut for numbers of the same length in div +999999999999999999999999999999999:999999999999999999999999999999999:1 +999999999999999999999999999999999:888888888888888888888888888888888:1 +999999999999999999999999999999999:777777777777777777777777777777777:1 +999999999999999999999999999999999:666666666666666666666666666666666:1 +999999999999999999999999999999999:555555555555555555555555555555555:1 +999999999999999999999999999999999:444444444444444444444444444444444:2 +999999999999999999999999999999999:333333333333333333333333333333333:3 +999999999999999999999999999999999:222222222222222222222222222222222:4 +999999999999999999999999999999999:111111111111111111111111111111111:9 +9999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3 +9999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3 +9999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3 +9999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4 +9999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9 +9999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99 +9999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999 +9999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999 +9999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999 +9999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999 +9999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999 +# bug with shortcut in Calc 0.44 +949418181818187070707070707070707070:181818181853535353535353535353535353:5 &bmodinv # format: number:modulus:result # bmodinv Data errors @@ -1679,6 +1787,13 @@ abc:1:abc:NaN 111111111111111111111111111111:111111111111111111111111111111:0 12345678901234567890:12345678901234567890:0 &bgcd +inf:12:NaN +-inf:12:NaN +12:inf:NaN +12:-inf:NaN +inf:inf:NaN +inf:-inf:NaN +-inf:-inf:NaN abc:abc:NaN abc:+0:NaN +0:abc:NaN @@ -1689,6 +1804,10 @@ abc:+0:NaN +2:+3:1 +3:+2:1 -3:+2:1 +-3:-2:1 +-144:-60:12 +144:-60:12 +144:60:12 100:625:25 4096:81:1 1034:804:2 @@ -1713,12 +1832,16 @@ abc:0:NaN +281474976710656:0:0 +281474976710656:1:0 +281474976710656:+281474976710656:281474976710656 +281474976710656:-1:281474976710656 -2:-3:-4 -1:-1:-1 -6:-6:-6 -7:-4:-8 -7:4:0 -4:7:4 +# negative argument is bitwise shorter than positive [perl #26559] +30:-3:28 +123:-1:123 # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0x0xFFFF 0xFFFFFF:0xFFFFFF:0x0xFFFFFF @@ -1750,6 +1873,11 @@ abc:0:NaN -6:-6:-6 -7:4:-3 -4:7:-1 ++281474976710656:-1:-1 +30:-3:-1 +30:-4:-2 +300:-76:-68 +-76:300:-68 # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0x0xFFFF 0xFFFFFF:0xFFFFFF:0x0xFFFFFF @@ -1798,6 +1926,10 @@ abc:0:NaN -4:7:-5 4:-7:-3 -4:-7:5 +30:-3:-29 +30:-4:-30 +300:-76:-360 +-76:300:-360 # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0 0xFFFFFF:0xFFFFFF:0 @@ -1912,8 +2044,8 @@ abc:12:NaN 0:0:1 0:1:0 0:2:0 -0:-1:NaN -0:-2:NaN +0:-1:inf +0:-2:inf 1:0:1 1:1:1 1:2:1 @@ -1926,14 +2058,40 @@ abc:12:NaN 2:2:4 2:3:8 3:3:27 +-2:2:4 +-2:3:-8 +-2:4:16 +-2:5:-32 2:-1:NaN -2:-1:NaN 2:-2:NaN -2:-2:NaN +# inf tests +inf:1234500012:inf --inf:1234500012:-inf +-inf:1234500012:inf +-inf:1234500013:-inf +inf:-12345000123:inf -inf:-12345000123:-inf +# -inf * -inf = inf +-inf:2:inf +-inf:0:NaN +-inf:-1:0 +-inf:inf:NaN +2:inf:inf +2:-inf:0 +0:inf:0 +0:-inf:inf +-1:-inf:NaN +-1:inf:NaN +-2:inf:NaN +-2:-inf:0 +NaN:inf:NaN +NaN:-inf:NaN +-inf:NaN:NaN +inf:NaN:NaN +inf:-inf:NaN +1:inf:1 +1:-inf:1 # 1 ** -x => 1 / (1 ** x) -1:0:1 -2:0:1 @@ -1956,6 +2114,14 @@ abc:12:NaN 10:9:1000000000 10:20:100000000000000000000 123456:2:15241383936 +-2:2:4 +-2:3:-8 +-2:4:16 +-2:5:-32 +-3:2:9 +-3:3:-27 +-3:4:81 +-3:5:-243 &length 100:3 10:2 @@ -2014,13 +2180,16 @@ NaN:inf:NaN # fourths root 16:4:2 81:4:3 -# 2 ** 32 +# 2 ** 64 18446744073709551616:4:65536 18446744073709551616:8:256 18446744073709551616:16:16 18446744073709551616:32:4 18446744073709551616:64:2 18446744073709551616:128:1 +# 213 ** 15 +84274086103068221283760416414557757:15:213 +# see t/bigroot for more tests &bsqrt 145:12 144:12 @@ -2040,6 +2209,9 @@ NaN:inf:NaN 152399026:12345 152399025:12345 152399024:12344 +# 2 ** 64 => 2 ** 32 +18446744073709551616:4294967296 +84274086103068221283760416414557757:290299993288095377 1:1 0:0 -2:NaN