diff options
Diffstat (limited to 'lib/Math/BigInt')
-rw-r--r-- | lib/Math/BigInt/Calc.pm | 102 | ||||
-rw-r--r-- | lib/Math/BigInt/CalcEmu.pm | 24 | ||||
-rw-r--r-- | lib/Math/BigInt/t/bare_mbf.t | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/bare_mbi.t | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/bigfltpm.inc | 63 | ||||
-rwxr-xr-x | lib/Math/BigInt/t/bigfltpm.t | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/bigintpm.inc | 44 | ||||
-rwxr-xr-x | lib/Math/BigInt/t/bigintpm.t | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/inf_nan.t | 76 | ||||
-rw-r--r-- | lib/Math/BigInt/t/lib_load.t | 45 | ||||
-rwxr-xr-x | lib/Math/BigInt/t/sub_mbf.t | 2 | ||||
-rwxr-xr-x | lib/Math/BigInt/t/sub_mbi.t | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/upgrade.inc | 2 | ||||
-rw-r--r-- | lib/Math/BigInt/t/with_sub.t | 2 |
14 files changed, 274 insertions, 96 deletions
diff --git a/lib/Math/BigInt/Calc.pm b/lib/Math/BigInt/Calc.pm index 3d53b0c414..41183f5e7c 100644 --- a/lib/Math/BigInt/Calc.pm +++ b/lib/Math/BigInt/Calc.pm @@ -6,7 +6,7 @@ use strict; use vars qw/$VERSION/; -$VERSION = '0.43'; +$VERSION = '0.44'; # Package to store unsigned big integers in decimal and do math with them @@ -36,7 +36,6 @@ $VERSION = '0.43'; sub api_version () { 1; } # constants for easier life -my $nan = 'NaN'; my ($MBASE,$BASE,$RBASE,$BASE_LEN,$MAX_VAL,$BASE_LEN_SMALL); my ($AND_BITS,$XOR_BITS,$OR_BITS); my ($AND_MASK,$XOR_MASK,$OR_MASK); @@ -71,7 +70,9 @@ sub _base_len $MBASE = int("1e".$BASE_LEN_SMALL); $RBASE = abs('1e-'.$BASE_LEN_SMALL); # see USE_MUL $MAX_VAL = $MBASE-1; - + + # avoid redefinitions + undef &_mul; undef &_div; @@ -132,13 +133,9 @@ BEGIN $e = 7 if $e > 7; # cap, for VMS, OS/390 and other 64 bit systems # 8 fails inside random testsuite, so take 7 - # determine how many digits fit into an integer and can be safely added - # together plus carry w/o causing an overflow - - use integer; - __PACKAGE__->_base_len($e); # set and store + use integer; # find out how many bits _and, _or and _xor can take (old default = 16) # I don't think anybody has yet 128 bit scalars, so let's play safe. local $^W = 0; # don't warn about 'nonportable number' @@ -221,11 +218,15 @@ sub _str # Convert number from internal base 100000 format to string format. # internal format is always normalized (no leading zeros, "-0" => "+0") my $ar = $_[1]; - my $ret = ""; - my $l = scalar @$ar; # number of parts - return $nan if $l < 1; # should not happen + my $l = scalar @$ar; # number of parts + if ($l < 1) # should not happen + { + require Carp; + Carp::croak("$_[1] has no elements"); + } + my $ret = ""; # handle first one different to strip leading zeros from it (there are no # leading zero parts in internal representation) $l --; $ret .= int($ar->[$l]); $l--; @@ -572,8 +573,19 @@ sub _div_use_mul # now calculate $x / $yorg if (length(int($yorg->[-1])) == length(int($x->[-1]))) { - # same length, so make full compare, and if equal, return 1 - # hm, same lengths, but same contents? So we need to check all parts: + + # We take a shortcut here, because the result must be + # between 1 and MAX_VAL (e.g. one element) and rem is not wanted. + if (!wantarray) + { + $x->[0] = int($x->[-1] / $yorg->[-1]); + splice(@$x,1); # keep single element + return $x; + } + + # wantarray: return (x,rem) + # same length, so make full compare + my $a = 0; my $j = scalar @$x - 1; # manual way (abort if unequal, good for early ne) while ($j >= 0) @@ -581,25 +593,17 @@ sub _div_use_mul last if ($a = $x->[$j] - $yorg->[$j]); $j--; } # $a contains the result of the compare between X and Y - # a < 0: x < y, a == 0 => x == y, a > 0: x > y + # a < 0: x < y, a == 0: x == y, a > 0: x > y if ($a <= 0) { - if (wantarray) - { - $rem = [ 0 ]; # a = 0 => x == y => rem 1 - $rem = [@$x] if $a != 0; # a < 0 => x < y => rem = x - } - splice(@$x,1); # keep single element - $x->[0] = 0; # if $a < 0 - if ($a == 0) - { - # $x == $y - $x->[0] = 1; - } - return ($x,$rem) if wantarray; - return $x; + $rem = [ 0 ]; # a = 0 => x == y => rem 0 + $rem = [@$x] if $a != 0; # a < 0 => x < y => rem = x + splice(@$x,1); # keep single element + $x->[0] = 0; # if $a < 0 + $x->[0] = 1 if $a == 0; # $x == $y + return ($x,$rem); } - # $x >= $y, proceed normally + # $x >= $y, so proceed normally } } @@ -766,8 +770,19 @@ sub _div_use_div if (length(int($yorg->[-1])) == length(int($x->[-1]))) { - # same length, so make full compare, and if equal, return 1 - # hm, same lengths, but same contents? So we need to check all parts: + + # We take a shortcut here, because the result must be + # between 1 and MAX_VAL (e.g. one element) and rem is not wanted. + if (!wantarray) + { + $x->[0] = int($x->[-1] / $yorg->[-1]); + splice(@$x,1); # keep single element + return $x; + } + + # wantarray: return (x,rem) + # same length, so make full compare + my $a = 0; my $j = scalar @$x - 1; # manual way (abort if unequal, good for early ne) while ($j >= 0) @@ -775,25 +790,18 @@ sub _div_use_div last if ($a = $x->[$j] - $yorg->[$j]); $j--; } # $a contains the result of the compare between X and Y - # a < 0: x < y, a == 0 => x == y, a > 0: x > y + # a < 0: x < y, a == 0: x == y, a > 0: x > y if ($a <= 0) { - if (wantarray) - { - $rem = [ 0 ]; # a = 0 => x == y => rem 1 - $rem = [@$x] if $a != 0; # a < 0 => x < y => rem = x - } + $rem = [ 0 ]; # a = 0 => x == y => rem 0 + $rem = [@$x] if $a != 0; # a < 0 => x < y => rem = x splice(@$x,1); # keep single element $x->[0] = 0; # if $a < 0 - if ($a == 0) - { - # $x == $y - $x->[0] = 1; - } - return ($x,$rem) if wantarray; - return $x; + $x->[0] = 1 if $a == 0; # $x == $y + return ($x,$rem); } # $x >= $y, so proceed normally + } } @@ -1928,7 +1936,7 @@ sub _gcd # greatest common divisor my ($c,$x,$y) = @_; - while (! _is_zero($c,$y)) + while ( (scalar @$y != 1) || ($y->[0] != 0) ) # while ($y != 0) { my $t = _copy($c,$y); $y = _mod($c, $x, $y); @@ -2103,8 +2111,8 @@ the same terms as Perl itself. Original math code by Mark Biggar, rewritten by Tels L<http://bloodgate.com/> in late 2000. Seperated from BigInt and shaped API with the help of John Peacock. -Fixed, sped-up and enhanced by Tels http://bloodgate.com 2001-2003. -Further streamlining (api_version 1) by Tels 2004. + +Fixed, speed-up, streamlined and enhanced by Tels 2001 - 2005. =head1 SEE ALSO diff --git a/lib/Math/BigInt/CalcEmu.pm b/lib/Math/BigInt/CalcEmu.pm index 9f7fd16434..f56b51a3b9 100644 --- a/lib/Math/BigInt/CalcEmu.pm +++ b/lib/Math/BigInt/CalcEmu.pm @@ -5,7 +5,7 @@ use strict; # use warnings; # dont use warnings for older Perls use vars qw/$VERSION/; -$VERSION = '0.04'; +$VERSION = '0.05'; package Math::BigInt; @@ -16,6 +16,8 @@ my $CALC_EMU; BEGIN { $CALC_EMU = Math::BigInt->config()->{'lib'}; + # register us with MBI to get notified of future lib changes + Math::BigInt::_register_callback( __PACKAGE__, sub { $CALC_EMU = $_[0]; } ); } sub __emu_band @@ -288,19 +290,27 @@ Math::BigInt::CalcEmu - Emulate low-level math with BigInt code =head1 SYNOPSIS + use Math::BigInt::CalcEmu; + +=head1 DESCRIPTION + Contains routines that emulate low-level math functions in BigInt, e.g. optional routines the low-level math package does not provide on it's own. -Will be loaded on demand and automatically by BigInt. - -Stuff here is really low-priority to optimize, -since it is far better to implement the operation in the low-level math -libary directly, possible even using a call to the native lib. +Will be loaded on demand and called automatically by BigInt. -=head1 DESCRIPTION +Stuff here is really low-priority to optimize, since it is far better to +implement the operation in the low-level math libary directly, possible even +using a call to the native lib. =head1 METHODS +=head2 __emu_bxor + +=head2 __emu_band + +=head2 __emu_bior + =head1 LICENSE This program is free software; you may redistribute it and/or modify it under diff --git a/lib/Math/BigInt/t/bare_mbf.t b/lib/Math/BigInt/t/bare_mbf.t index a79dff1bb3..9a12572e14 100644 --- a/lib/Math/BigInt/t/bare_mbf.t +++ b/lib/Math/BigInt/t/bare_mbf.t @@ -27,7 +27,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 1924; + plan tests => 1992; } use Math::BigFloat lib => 'BareCalc'; diff --git a/lib/Math/BigInt/t/bare_mbi.t b/lib/Math/BigInt/t/bare_mbi.t index 6695492521..bf08a90f34 100644 --- a/lib/Math/BigInt/t/bare_mbi.t +++ b/lib/Math/BigInt/t/bare_mbi.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 2952; + plan tests => 3012; } use Math::BigInt lib => 'BareCalc'; diff --git a/lib/Math/BigInt/t/bigfltpm.inc b/lib/Math/BigInt/t/bigfltpm.inc index 131e4531b9..5f27a8b8cb 100644 --- a/lib/Math/BigInt/t/bigfltpm.inc +++ b/lib/Math/BigInt/t/bigfltpm.inc @@ -4,6 +4,8 @@ ok ($class->config()->{lib},$CL); use strict; +my $z; + while (<DATA>) { chomp; @@ -87,7 +89,27 @@ while (<DATA>) else { $try .= "\$y = $class->new(\"$args[1]\");"; - if ($f eq "fcmp") { + + if ($f eq "bgcd") + { + if (defined $args[2]) + { + $try .= " \$z = $class->new(\"$args[2]\"); "; + } + $try .= "$class\::bgcd(\$x, \$y"; + $try .= ", \$z" if (defined $args[2]); + $try .= " );"; + } + elsif ($f eq "blcm") + { + if (defined $args[2]) + { + $try .= " \$z = $class->new(\"$args[2]\"); "; + } + $try .= "$class\::blcm(\$x, \$y"; + $try .= ", \$z" if (defined $args[2]); + $try .= " );"; + } elsif ($f eq "fcmp") { $try .= '$x <=> $y;'; } elsif ($f eq "facmp") { $try .= '$x->facmp($y);'; @@ -115,6 +137,7 @@ while (<DATA>) } # print "# Trying: '$try'\n"; $ans1 = eval $try; + print "# Error: $@\n" if $@; if ($ans =~ m|^/(.*)$|) { my $pat = $1; @@ -337,6 +360,42 @@ sub ok_undef } __DATA__ +&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 ++0:+0:0 ++0:+1:1 ++1:+0:1 ++1:+1:1 ++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 +27:90:56:1 +27:90:54:9 +&blcm +abc:abc:NaN +abc:+0:NaN ++0:abc:NaN ++0:+0:NaN ++1:+0:0 ++0:+1:0 ++27:+90:270 ++1034:+804:415668 $div_scale = 40; &flog 0::NaN @@ -1479,7 +1538,7 @@ abc:0 1200:1 -1200:1 &is_positive -0:1 +0:0 1:1 -1:0 -123:0 diff --git a/lib/Math/BigInt/t/bigfltpm.t b/lib/Math/BigInt/t/bigfltpm.t index 238a23fced..5cc9ddbbda 100755 --- a/lib/Math/BigInt/t/bigfltpm.t +++ b/lib/Math/BigInt/t/bigfltpm.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 1924 + plan tests => 1992 + 2; # own tests } diff --git a/lib/Math/BigInt/t/bigintpm.inc b/lib/Math/BigInt/t/bigintpm.inc index 6453879048..2a2bfe11e9 100644 --- a/lib/Math/BigInt/t/bigintpm.inc +++ b/lib/Math/BigInt/t/bigintpm.inc @@ -778,7 +778,7 @@ inf:inf:NaN -inf:1 NaNneg:0 &is_positive -0:1 +0:0 -1:0 1:1 +inf:1 @@ -1497,6 +1497,27 @@ inf:0:inf,inf 1234567890999999999:9876543210:124999998,9503086419 1234567890000000000:9876543210:124999998,8503086420 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451 +# 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 @@ -1591,6 +1612,27 @@ 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 &bmodinv # format: number:modulus:result # bmodinv Data errors diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t index 6cd19f9b6f..16f4d32a30 100755 --- a/lib/Math/BigInt/t/bigintpm.t +++ b/lib/Math/BigInt/t/bigintpm.t @@ -10,7 +10,7 @@ BEGIN my $location = $0; $location =~ s/bigintpm.t//; unshift @INC, $location; # to locate the testing files chdir 't' if -d 't'; - plan tests => 2952; + plan tests => 3012; } use Math::BigInt; diff --git a/lib/Math/BigInt/t/inf_nan.t b/lib/Math/BigInt/t/inf_nan.t index 852ffed7bd..0e5294fe44 100644 --- a/lib/Math/BigInt/t/inf_nan.t +++ b/lib/Math/BigInt/t/inf_nan.t @@ -3,16 +3,11 @@ # test inf/NaN handling all in one place # Thanx to Jarkko for the excellent explanations and the tables -use Test; +use Test::More; use strict; BEGIN { - chdir 't' if -d 't'; - unshift @INC, '../lib'; - } -BEGIN - { $| = 1; # to locate the testing files my $location = $0; $location =~ s/inf_nan.t//i; @@ -35,7 +30,9 @@ BEGIN # values groups operators classes tests plan tests => 7 * 6 * 5 * 4 * 2 + - 7 * 6 * 2 * 4 * 1; # bmod + 7 * 6 * 2 * 4 * 1 # bmod +; +# see bottom: + 4 * 10; # 4 classes * 10 NaN == NaN tests } use Math::BigInt; @@ -109,10 +106,8 @@ foreach (qw/ $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 my $r = $x->badd($y); - print "# x $class $args[0] + $args[1] should be $args[2] but is $x\n", - if !ok ($x->bstr(),$args[2]); - print "# r $class $args[0] + $args[1] should be $args[2] but is $r\n", - if !ok ($x->bstr(),$args[2]); + is($x->bstr(),$args[2],"x $class $args[0] + $args[1]"); + is($x->bstr(),$args[2],"r $class $args[0] + $args[1]"); } } @@ -175,10 +170,8 @@ foreach (qw/ $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 my $r = $x->bsub($y); - print "# x $class $args[0] - $args[1] should be $args[2] but is $x\n" - if !ok ($x->bstr(),$args[2]); - print "# r $class $args[0] - $args[1] should be $args[2] but is $r\n" - if !ok ($r->bstr(),$args[2]); + is($x->bstr(),$args[2],"x $class $args[0] - $args[1]"); + is($r->bstr(),$args[2],"r $class $args[0] - $args[1]"); } } @@ -242,10 +235,8 @@ foreach (qw/ $args[2] = '0' if $args[2] eq '-0'; # BigInt hasn't got -0 my $r = $x->bmul($y); - print "# x $class $args[0] * $args[1] should be $args[2] but is $x\n" - if !ok ($x->bstr(),$args[2]); - print "# r $class $args[0] * $args[1] should be $args[2] but is $r\n" - if !ok ($r->bstr(),$args[2]); + is($x->bstr(),$args[2],"x $class $args[0] * $args[1]"); + is($r->bstr(),$args[2],"r $class $args[0] * $args[1]"); } } @@ -312,30 +303,53 @@ foreach (qw/ # bdiv in scalar context my $r = $x->bdiv($y); - print "# x $class $args[0] / $args[1] should be $args[2] but is $x\n" - if !ok ($x->bstr(),$args[2]); - print "# r $class $args[0] / $args[1] should be $args[2] but is $r\n" - if !ok ($r->bstr(),$args[2]); + is($x->bstr(),$args[2],"x $class $args[0] / $args[1]"); + is($r->bstr(),$args[2],"r $class $args[0] / $args[1]"); # bmod and bdiv in list context my ($d,$rem) = $t->bdiv($y); # bdiv in list context - print "# t $class $args[0] / $args[1] should be $args[2] but is $t\n" - if !ok ($t->bstr(),$args[2]); - print "# d $class $args[0] / $args[1] should be $args[2] but is $d\n" - if !ok ($d->bstr(),$args[2]); + is($t->bstr(),$args[2],"t $class $args[0] / $args[1]"); + is($d->bstr(),$args[2],"d $class $args[0] / $args[1]"); # bmod my $m = $tmod->bmod($y); # bmod() agrees with bdiv? - print "# m $class $args[0] % $args[1] should be $rem but is $m\n" - if !ok ($m->bstr(),$rem->bstr()); + is($m->bstr(),$rem->bstr(),"m $class $args[0] % $args[1]"); # bmod() return agrees with set value? - print "# o $class $args[0] % $args[1] should be $m ($rem) but is $tmod\n" - if !ok ($tmod->bstr(),$m->bstr()); + is($tmod->bstr(),$m->bstr(),"o $class $args[0] % $args[1]"); } } +############################################################################# +# overloaded comparisations + +# these are disabled for now, since Perl itself can't seem to make up it's +# mind what NaN actually is, see [perl #33106]. + +# +#foreach my $c (@classes) +# { +# my $x = $c->bnan(); +# my $y = $c->bnan(); # test with two different objects, too +# my $a = $c->bzero(); +# +# is ($x == $y, undef, 'NaN == NaN: undef'); +# is ($x != $y, 1, 'NaN != NaN: 1'); +# +# is ($x == $x, undef, 'NaN == NaN: undef'); +# is ($x != $x, 1, 'NaN != NaN: 1'); +# +# is ($a != $x, 1, '0 != NaN: 1'); +# is ($a == $x, undef, '0 == NaN: undef'); +# +# is ($a < $x, undef, '0 < NaN: undef'); +# is ($a <= $x, undef, '0 <= NaN: undef'); +# is ($a >= $x, undef, '0 >= NaN: undef'); +# is ($a > $x, undef, '0 > NaN: undef'); +# } + +# All done. diff --git a/lib/Math/BigInt/t/lib_load.t b/lib/Math/BigInt/t/lib_load.t new file mode 100644 index 0000000000..3aff7c4037 --- /dev/null +++ b/lib/Math/BigInt/t/lib_load.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w + +use Test::More; +use strict; + +BEGIN + { + $| = 1; + # to locate the testing files + my $location = $0; $location =~ s/sub_mbf.t//i; + if ($ENV{PERL_CORE}) + { + # testing with the core distribution + @INC = qw(../t/lib); + } + unshift @INC, '../lib'; + if (-d 't') + { + chdir 't'; + require File::Spec; + unshift @INC, File::Spec->catdir(File::Spec->updir, $location); + } + else + { + unshift @INC, $location; + } + print "# INC = @INC\n"; + + plan tests => 2; + } + +# first load BigInt with Calc +use Math::BigInt lib => 'Calc'; + +# BigFloat will remember that we loaded Calc +require Math::BigFloat; +is (Math::BigFloat::config()->{lib}, 'Math::BigInt::Calc', 'BigFloat got Calc'); + +# now load BigInt again with a different lib +Math::BigInt->import( lib => 'BareCalc' ); + +# and finally test that BigFloat knows about BareCalc + +is (Math::BigFloat::config()->{lib}, 'Math::BigInt::BareCalc', 'BigFloat was notified'); + diff --git a/lib/Math/BigInt/t/sub_mbf.t b/lib/Math/BigInt/t/sub_mbf.t index e9209b70c4..73d7fc0e21 100755 --- a/lib/Math/BigInt/t/sub_mbf.t +++ b/lib/Math/BigInt/t/sub_mbf.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 1924 + plan tests => 1992 + 6; # + our own tests } diff --git a/lib/Math/BigInt/t/sub_mbi.t b/lib/Math/BigInt/t/sub_mbi.t index ee48b81234..4d4fc4eada 100755 --- a/lib/Math/BigInt/t/sub_mbi.t +++ b/lib/Math/BigInt/t/sub_mbi.t @@ -26,7 +26,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 2952 + plan tests => 3012 + 5; # +5 own tests } diff --git a/lib/Math/BigInt/t/upgrade.inc b/lib/Math/BigInt/t/upgrade.inc index aac4a055eb..6545edb6e4 100644 --- a/lib/Math/BigInt/t/upgrade.inc +++ b/lib/Math/BigInt/t/upgrade.inc @@ -295,7 +295,7 @@ __DATA__ -inf:1 NaNneg:0 &is_positive -0:1 +0:0 -1:0 1:1 +inf:1 diff --git a/lib/Math/BigInt/t/with_sub.t b/lib/Math/BigInt/t/with_sub.t index 8611e45b12..0ed85a4f4c 100644 --- a/lib/Math/BigInt/t/with_sub.t +++ b/lib/Math/BigInt/t/with_sub.t @@ -28,7 +28,7 @@ BEGIN } print "# INC = @INC\n"; - plan tests => 1924 + plan tests => 1992 + 1; } |