diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2001-08-05 22:46:10 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2001-08-05 22:46:10 +0000 |
commit | 574bacfe464e67c186e160f356e339f5a9faa3e8 (patch) | |
tree | 5040680d4df675fff5ca63fc6d2220fb7d720525 /lib/Math/BigInt/t/bigintpm.t | |
parent | 6d0cc0d743fcf15e2f42426a114c8bb442562080 (diff) | |
download | perl-574bacfe464e67c186e160f356e339f5a9faa3e8.tar.gz |
Upgrade to Math::BigInt 1.40.
NOTE: this patch necessitates doing something about
infinity handling since the new bigintpm.t tests use
infinity, which causes SIGFPEs at least in Tru64.
p4raw-id: //depot/perl@11591
Diffstat (limited to 'lib/Math/BigInt/t/bigintpm.t')
-rwxr-xr-x | lib/Math/BigInt/t/bigintpm.t | 227 |
1 files changed, 199 insertions, 28 deletions
diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t index f2663de26d..9e84e20ee6 100755 --- a/lib/Math/BigInt/t/bigintpm.t +++ b/lib/Math/BigInt/t/bigintpm.t @@ -8,9 +8,9 @@ BEGIN $| = 1; # chdir 't' if -d 't'; unshift @INC, '../lib'; # for running manually - plan tests => 1222; + plan tests => 1424; } -my $version = '1.36'; # for $VERSION tests, match current release (by hand!) +my $version = '1.40'; # for $VERSION tests, match current release (by hand!) ############################################################################## # for testing inheritance of _swap @@ -18,6 +18,7 @@ my $version = '1.36'; # for $VERSION tests, match current release (by hand!) package Math::Foo; use Math::BigInt; +#use Math::BigInt lib => 'BitVect'; # for testing use vars qw/@ISA/; @ISA = (qw/Math::BigInt/); @@ -46,9 +47,8 @@ package main; use Math::BigInt; #use Math::BigInt lib => 'BitVect'; # for testing -#use Math::BigInt lib => 'Small'; # for testing -my $CALC = Math::BigInt::_core_lib(); +my $CALC = Math::BigInt::_core_lib(); ok ($CALC,'Math::BigInt::Calc'); my (@args,$f,$try,$x,$y,$z,$a,$exp,$ans,$ans1,@a,$m,$e,$round_mode); @@ -81,10 +81,18 @@ while (<DATA>) $try .= '$x->is_odd()+0;'; } elsif ($f eq "is_even") { $try .= '$x->is_even()+0;'; + } elsif ($f eq "is_negative") { + $try .= '$x->is_negative()+0;'; + } elsif ($f eq "is_positive") { + $try .= '$x->is_positive()+0;'; } elsif ($f eq "is_inf") { $try .= "\$x->is_inf('$args[1]')+0;"; } elsif ($f eq "binf") { $try .= "\$x->binf('$args[1]');"; + } elsif ($f eq "bone") { + $try .= "\$x->bone('$args[1]');"; + } elsif ($f eq "bnan") { + $try .= "\$x->bnan();"; } elsif ($f eq "bfloor") { $try .= '$x->bfloor();'; } elsif ($f eq "bceil") { @@ -92,9 +100,9 @@ while (<DATA>) } elsif ($f eq "bsstr") { $try .= '$x->bsstr();'; } elsif ($f eq "bneg") { - $try .= '-$x;'; + $try .= '$x->bneg();'; } elsif ($f eq "babs") { - $try .= 'abs $x;'; + $try .= '$x->babs();'; } elsif ($f eq "binc") { $try .= '++$x;'; } elsif ($f eq "bdec") { @@ -130,6 +138,8 @@ while (<DATA>) $try .= "\$x * \$y;"; }elsif ($f eq "bdiv"){ $try .= "\$x / \$y;"; + }elsif ($f eq "bdiv-list"){ + $try .= 'join (",",$x->bdiv($y));'; }elsif ($f eq "bmod"){ $try .= "\$x % \$y;"; }elsif ($f eq "bgcd") @@ -199,7 +209,7 @@ while (<DATA>) } # endwhile data tests close DATA; -# XXX Tels 06/29/2001 following tests never fail or do not work :( +# XXX Tels 06/29/2001 following tests never fail or do not work :( !? # test whether use Math::BigInt qw/version/ works $try = "use Math::BigInt ($version.'1');"; @@ -214,21 +224,27 @@ $ans1 = eval $try; ok ( $ans1, "1427247692705959881058285969449495136382746624"); # test wether Math::BigInt::Small via use works (w/ dff. spellings of calc) -#$try = "use Math::BigInt ($version,'CALC','Small');"; +#$try = "use Math::BigInt ($version,'lib','Small');"; #$try .= ' $x = 2**10; $x = "$x";'; #$ans1 = eval $try; #ok ( $ans1, "1024"); -#$try = "use Math::BigInt ($version,'cAlC','Math::BigInt::Small');"; +#$try = "use Math::BigInt ($version,'LiB','Math::BigInt::Small');"; #$try .= ' $x = 2**10; $x = "$x";'; #$ans1 = eval $try; #ok ( $ans1, "1024"); # test wether calc => undef (array element not existing) works -#$try = "use Math::BigInt ($version,'CALC');"; +#$try = "use Math::BigInt ($version,'LIB');"; #$try = "require Math::BigInt; Math::BigInt::import($version,'CALC');"; #$try .= ' $x = Math::BigInt->new(2)**10; $x = "$x";'; #$ans1 = eval $try; #ok ( $ans1, 1024); +# test whether fallback to calc works +$try = "use Math::BigInt ($version,'lib','foo, bar , ');"; +$try .= ' Math::BigInt::_core_lib();'; +$ans1 = eval $try; +ok ( $ans1, "Math::BigInt::Calc"); + # test some more @a = (); for (my $i = 1; $i < 10; $i++) @@ -237,11 +253,16 @@ for (my $i = 1; $i < 10; $i++) } ok "@a", "1 2 3 4 5 6 7 8 9"; -# test whether selfmultiplication works correctly (result is 2**64) +# test whether self-multiplication works correctly (result is 2**64) $try = '$x = new Math::BigInt "+4294967296";'; $try .= '$a = $x->bmul($x);'; $ans1 = eval $try; print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(2) ** 64); +# test self-pow +$try = '$x = Math::BigInt->new(10);'; +$try .= '$a = $x->bpow($x);'; +$ans1 = eval $try; +print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(10) ** 10); # test whether op destroys args or not (should better not) @@ -343,6 +364,9 @@ $ans = eval $try; print "# For '$try'\n" if (!ok "$ans" , "ok" ); ############################################################################### +# the followin tests only make sense with Math::BigInt::Calc + +############################################################################### # check proper length of internal arrays $x = Math::BigInt->new(99999); is_valid($x); @@ -350,8 +374,7 @@ $x += 1; ok ($x,100000); is_valid($x); $x -= 1; ok ($x,99999); is_valid($x); ############################################################################### -# check numify, these tests only make sense with Math::BigInt::Calc, since -# only this uses $BASE +# check numify my $BASE = int(1e5); # should access Math::BigInt::Calc::BASE $x = Math::BigInt->new($BASE-1); ok ($x->numify(),$BASE-1); @@ -380,6 +403,25 @@ ok ($z, 100000); ok ($x, 23456); ############################################################################### +# bug in shortcut in mul() + +# construct a number with a zero-hole of BASE_LEN +my $bl = Math::BigInt::Calc::_base_len(); +$x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl; +$y = '1' x (2*$bl); +#print "$x * $y\n"; +$x = Math::BigInt->new($x)->bmul($y); +# result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl +$y = ''; my $d = ''; +for (my $i = 1; $i <= $bl; $i++) + { + $y .= $i; $d = $i.$d; + } +#print "$y $d\n"; +$y .= $bl x (3*$bl-1) . $d . '0' x $bl; +ok ($x,$y); + +############################################################################### # bug with rest "-0" in div, causing further div()s to fail $x = Math::BigInt->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); @@ -477,6 +519,12 @@ ok ($x,-3); ok (ref($x),'Math::Foo'); ############################################################################### +# test whether +inf eq inf + +$y = 1e1000000; # create inf, since bareword inf does not work +$x = Math::BigInt->new('+inf'); ok ($x,$y); + +############################################################################### # all tests done ############################################################################### @@ -516,6 +564,20 @@ sub is_valid } __END__ +&is_negative +0:0 +-1:1 +1:0 ++inf:0 +-inf:1 +NaNneg:0 +&is_positive +0:1 +-1:0 +1:1 ++inf:1 +-inf:0 +NaNneg:0 &is_odd abc:0 0:0 @@ -548,6 +610,24 @@ abc:0 +987654321:+123456789:1 -987654321:+123456789:1 -123:+4567889:-1 +# NaNs +acmpNaN:123: +123:acmpNaN: +acmpNaN:acmpNaN: +# infinity ++inf:+inf:0 +-inf:-inf:0 ++inf:-inf:0 +-inf:+inf:0 ++inf:123:1 +-inf:123:1 ++inf:-123:1 +-inf:-123:1 +# return undef ++inf:NaN: +NaN:inf: +-inf:NaN: +NaN:-inf: &bnorm 123:123 # binary input @@ -561,6 +641,8 @@ abc:0 0b011:3 0b101:5 0b1000000000000000000000000000000:1073741824 +0b_101:NaN +0b1_0_1:5 # hex input -0x0:0 0xabcdefgh:NaN @@ -569,8 +651,10 @@ abc:0 -0xABCDEF:-11259375 -0x1234:-4660 0x12345678:305419896 +0x1_2_3_4_56_78:305419896 +0x_123:NaN # inf input -+inf:+inf ++inf:inf -inf:-inf 0inf:NaN # normal input @@ -621,10 +705,22 @@ E23:NaN -1010E-2:NaN -1.01E+1:NaN -1.01E-1:NaN +1234.00:1234 +&bnan +1:NaN +2:NaN +abc:NaN +&bone +2:+:+1 +2:-:-1 +boneNaN:-:-1 +boneNaN:+:+1 +2:abc:+1 +3::+1 &binf -1:+:+inf +1:+:inf 2:-:-inf -3:abc:+inf +3:abc:inf &is_inf +inf::1 -inf::1 @@ -677,6 +773,9 @@ abc:abc:NaN 100:1e+2 abc:NaN &bneg +bnegNaN:NaN ++inf:-inf +-inf:inf abd:NaN +0:+0 +1:-1 @@ -684,16 +783,18 @@ abd:NaN +123456789:-123456789 -123456789:+123456789 &babs -abc:NaN +babsNaN:NaN ++inf:inf +-inf:inf +0:+0 +1:+1 -1:+1 +123456789:+123456789 -123456789:+123456789 &bcmp -abc:abc: -abc:+0: -+0:abc: +bcmpNaN:bcmpNaN: +bcmpNaN:+0: ++0:bcmpNaN: +0:+0:0 -1:+0:-1 +0:-1:1 @@ -723,18 +824,24 @@ abc:+0: +inf:-5432112345:1 +inf:+inf:0 -inf:-inf:0 ++inf:-inf:1 +-inf:+inf:-1 # return undef +inf:NaN: -NaN:+inf: +NaN:inf: -inf:NaN: NaN:-inf: &binc abc:NaN ++inf:inf +-inf:-inf +0:+1 +1:+2 -1:+0 &bdec abc:NaN ++inf:inf +-inf:-inf +0:-1 +1:+0 -1:-2 @@ -742,6 +849,14 @@ abc:NaN abc:abc:NaN abc:+0:NaN +0:abc:NaN ++inf:-inf:0 +-inf:+inf:0 ++inf:+inf:inf +-inf:-inf:-inf +baddNaN:+inf:NaN +baddNaN:+inf:NaN ++inf:baddNaN:NaN +-inf:baddNaN:NaN +0:+0:+0 +1:+0:+1 +0:+1:+1 @@ -780,6 +895,10 @@ abc:+0:NaN abc:abc:NaN abc:+0:NaN +0:abc:NaN ++inf:-inf:inf +-inf:+inf:-inf ++inf:+inf:0 +-inf:-inf:0 +0:+0:+0 +1:+0:+1 +0:+1:-1 @@ -818,6 +937,14 @@ abc:+0:NaN abc:abc:NaN abc:+0:NaN +0:abc:NaN +NaNmul:+inf:NaN +NaNmul:-inf:NaN +-inf:NaNmul:NaN ++inf:NaNmul:NaN ++inf:+inf:inf ++inf:-inf:-inf +-inf:+inf:-inf +-inf:-inf:inf +0:+0:+0 +0:+1:+0 +1:+0:+0 @@ -850,18 +977,23 @@ abc:+0:NaN +25:+25:+625 +12345:+12345:+152399025 +99999:+11111:+1111088889 +&bdiv-list +100:20:5,0 +4095:4095:1,0 +-4095:-4095:1,0 +4095:-4095:-1,0 +-4095:4095:-1,0 &bdiv abc:abc:NaN abc:+1:abc:NaN -# really? -#+5:0:+inf -#-5:0:-inf +1:abc:NaN +0:+0:NaN ++5:0:inf +-5:0:-inf ++1:+0:inf +0:+1:+0 -+1:+0:NaN +0:-1:+0 --1:+0:NaN +-1:+0:-inf +1:+1:+1 -1:-1:+1 +1:-1:-1 @@ -900,6 +1032,8 @@ abc:+1:abc:NaN 1:-3:-1 -5:3:-2 4:-3:-2 +123:+inf:0 +123:-inf:0 &bmod abc:abc:NaN abc:+1:abc:NaN @@ -948,6 +1082,7 @@ abc:+1:abc:NaN -2:-3:-2 4:-3:-2 1:-3:-2 +4095:4095:0 &bgcd abc:abc:NaN abc:+0:NaN @@ -983,6 +1118,12 @@ abc:0:NaN +281474976710656:+0:+0 +281474976710656:+1:+0 +281474976710656:+281474976710656:+281474976710656 +-2:-3:-4 +-1:-1:-1 +-6:-6:-6 +-7:-4:-8 +-7:4:0 +-4:7:4 &bior abc:abc:NaN abc:0:NaN @@ -992,6 +1133,11 @@ abc:0:NaN +281474976710656:+0:+281474976710656 +281474976710656:+1:+281474976710657 +281474976710656:+281474976710656:+281474976710656 +-2:-3:-1 +-1:-1:-1 +-6:-6:-6 +-7:4:-3 +-4:7:-1 &bxor abc:abc:NaN abc:0:NaN @@ -1001,11 +1147,21 @@ abc:0:NaN +281474976710656:+0:+281474976710656 +281474976710656:+1:+281474976710657 +281474976710656:+281474976710656:+0 +-2:-3:3 +-1:-1:0 +-6:-6:0 +-7:4:-3 +-4:7:-5 +4:-7:-3 +-4:-7:5 &bnot abc:NaN +0:-1 +8:-9 +281474976710656:-281474976710657 +-1:0 +-2:1 +-12:11 &digit 0:0:0 12:0:2 @@ -1075,9 +1231,9 @@ abc:12:NaN -2:-1:NaN 2:-2:NaN -2:-2:NaN -+inf:1234500012:+inf ++inf:1234500012:inf -inf:1234500012:-inf -+inf:-12345000123:+inf ++inf:-12345000123:inf -inf:-12345000123:-inf # 1 ** -x => 1 / (1 ** x) -1:0:1 @@ -1124,6 +1280,10 @@ abc:12:NaN Nan:NaN &bround $round_mode('trunc') +0:12:0 +NaNbround:12:NaN ++inf:12:inf +-inf:12:-inf 1234:0:1234 1234:2:1200 123456:4:123400 @@ -1201,11 +1361,16 @@ $round_mode('even') &is_zero 0:1 NaNzero:0 ++inf:0 +-inf:0 123:0 -1:0 1:0 &is_one 0:0 +NaNone:0 ++inf:0 +-inf:0 1:1 2:0 -1:0 @@ -1213,12 +1378,18 @@ NaNzero:0 # floor and ceil tests are pretty pointless in integer space...but play safe &bfloor 0:0 +NaNfloor:NaN ++inf:inf +-inf:-inf -1:-1 -2:-2 2:2 3:3 abc:NaN &bceil +NaNceil:NaN ++inf:inf +-inf:-inf 0:0 -1:-1 -2:-2 |