diff options
author | 2019-02-13 21:15:00 +0000 | |
---|---|---|
committer | 2019-02-13 21:15:00 +0000 | |
commit | 9f11ffb7133c203312a01e4b986886bc88c7d74b (patch) | |
tree | 6618511204c614b20256e4ef9dea39a7b311d638 /gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc | |
parent | Import perl-5.28.1 (diff) | |
download | wireguard-openbsd-9f11ffb7133c203312a01e4b986886bc88c7d74b.tar.xz wireguard-openbsd-9f11ffb7133c203312a01e4b986886bc88c7d74b.zip |
Fix merge issues, remove excess files - match perl-5.28.1 dist
looking good sthen@, Great! bluhm@
Diffstat (limited to 'gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc')
5 files changed, 103 insertions, 64 deletions
diff --git a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/FastCalc.xs b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/FastCalc.xs index eb228e4ca56..f8bb3140e89 100644 --- a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/FastCalc.xs +++ b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/FastCalc.xs @@ -152,7 +152,7 @@ __strip_zeros(x) elems = av_len(a); /* number of elems in array */ ST(0) = x; /* we return x */ if (elems == -1) - { + { av_push (a, newSViv(0)); /* correct empty arrays */ XSRETURN(1); } @@ -210,13 +210,13 @@ _dec(class,x) } sv_setnv (temp, MAX); /* overflow, so set this to $MAX */ index++; - } + } /* do have more than one element? */ /* (more than one because [0] should be kept as single-element) */ if (elems > 0) { temp = *av_fetch(a, elems, 0); /* fetch last element */ - if (SvIV(temp) == 0) /* did last elem overflow? */ + if (SvIV(temp) == 0) /* did last elem overflow? */ { av_pop(a); /* yes, so shrink array */ /* aka remove leading zeros */ @@ -254,7 +254,7 @@ _inc(class,x) } sv_setiv (temp, 0); /* overflow, so set this elem to 0 */ index++; - } + } temp = *av_fetch(a, elems, 0); /* fetch last element */ if (SvIV(temp) == 0) /* did last elem overflow? */ { @@ -394,10 +394,10 @@ _acmp(class, cx, cy); diff_nv = SvNV(tempx) - SvNV(tempy); if (diff_nv != 0) { - break; + break; } elemsx--; - } + } if (diff_nv > 0) { RETURN_MORTAL_INT(1); @@ -407,4 +407,3 @@ _acmp(class, cx, cy); RETURN_MORTAL_INT(-1); } ST(0) = sv_2mortal(newSViv(0)); /* X and Y are equal */ - diff --git a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bigintfc.t b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bigintfc.t index c8751ad81bd..a3dd4a8d37c 100755 --- a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bigintfc.t +++ b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bigintfc.t @@ -148,17 +148,17 @@ $x = $C->_new("123000"); is ($C->_zeros($x),3); $x = $C->_new("0"); is ($C->_zeros($x),0); # _lsft, _rsft -$x = $C->_new("10"); $y = $C->_new("3"); +$x = $C->_new("10"); $y = $C->_new("3"); is ($C->_str($C->_lsft($x,$y,10)),10000); -$x = $C->_new("20"); $y = $C->_new("3"); +$x = $C->_new("20"); $y = $C->_new("3"); is ($C->_str($C->_lsft($x,$y,10)),20000); $x = $C->_new("128"); $y = $C->_new("4"); is ($C->_str($C->_lsft($x,$y,2)), 128 << 4); -$x = $C->_new("1000"); $y = $C->_new("3"); +$x = $C->_new("1000"); $y = $C->_new("3"); is ($C->_str($C->_rsft($x,$y,10)),1); -$x = $C->_new("20000"); $y = $C->_new("3"); +$x = $C->_new("20000"); $y = $C->_new("3"); is ($C->_str($C->_rsft($x,$y,10)),20); $x = $C->_new("256"); $y = $C->_new("4"); is ($C->_str($C->_rsft($x,$y,2)),256 >> 4); @@ -211,13 +211,13 @@ $x = $C->_new("3333"); $y = $C->_new("1111"); is ($C->_str(scalar $C->_div($x,$y)),3); $x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); is ($C->_str($x),30); is ($C->_str($y),3); -$x = $C->_new("123"); $y = $C->_new("1111"); +$x = $C->_new("123"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); is ($C->_str($x),0); is ($C->_str($y),123); # _num foreach (qw/1 12 123 1234 12345 1234567 12345678 123456789 1234567890/) { - $x = $C->_new("$_"); + $x = $C->_new("$_"); is (ref($x),'ARRAY'); is ($C->_str($x),"$_"); $x = $C->_num($x); is (ref($x),''); is ($x,$_); } @@ -242,7 +242,7 @@ is ($C->_str($C->_pow($x,$n)), 1); $x = $C->_new("5"); $n = $C->_new("1"); # x ** 1 => x is ($C->_str($C->_pow($x,$n)), 5); -$x = $C->_new("81"); $n = $C->_new("3"); # 81 ** 3 == 531441 +$x = $C->_new("81"); $n = $C->_new("3"); # 81 ** 3 == 531441 is ($C->_str($C->_pow($x,$n)),81 ** 3); is ($C->_str($C->_root($x,$n)),81); @@ -254,7 +254,7 @@ is ($C->_str($C->_pow($x,$n)),'150094635296999121'); # 531441 ** 3 == is ($C->_str($C->_root($x,$n)),'531441'); is ($C->_str($C->_root($x,$n)),'81'); -$x = $C->_new("81"); $n = $C->_new("14"); +$x = $C->_new("81"); $n = $C->_new("14"); is ($C->_str($C->_pow($x,$n)),'523347633027360537213511521'); is ($C->_str($C->_root($x,$n)),'81'); @@ -274,7 +274,7 @@ for my $i (2 .. 9) my $rc = '9' x ($i-1). '8' . '0' x ($i-1) . '1'; print "# _pow( ", '9' x $i, ", 2) \n" unless is ($C->_str($C->_pow($x,$n)),$rc); - + if ($i <= 7) { $x = '9' x $i; $x = $C->_new($x); @@ -333,11 +333,7 @@ foreach (qw/999 9999 99999 9999999 99999999 999999999 9999999999 99999999999/) $x = $C->_new("1000"); $C->_inc($x); is ($C->_str($x),'1001'); $C->_dec($x); is ($C->_str($x),'1000'); -my $BL; -{ - no strict 'refs'; - $BL = &{"$C"."::_base_len"}(); -} +my $BL = $C -> _base_len(); $x = '1' . '0' x $BL; $z = '1' . '0' x ($BL-1); $z .= '1'; @@ -427,4 +423,3 @@ is ($C->_check(123),'123 is not a reference'); # done 1; - diff --git a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bootstrap.t b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bootstrap.t index d73afcb47c1..6f94bebc883 100755 --- a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bootstrap.t +++ b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/bootstrap.t @@ -5,4 +5,3 @@ use Test::More tests => 1; BEGIN { use_ok('Math::BigInt::FastCalc'); } - diff --git a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/leak.t b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/leak.t index 5db38e1dbd9..6d0f7464a57 100755 --- a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/leak.t +++ b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/leak.t @@ -12,7 +12,9 @@ use Math::BigInt::FastCalc; ############################################################################# package Math::BigInt::FastCalc::LeakCheck; -use parent qw(Math::BigInt::FastCalc); + +use Math::BigInt::FastCalc; +our @ISA = qw< Math::BigInt::FastCalc >; my $destroyed = 0; sub DESTROY { $destroyed++; } @@ -76,4 +78,3 @@ sub _test_acmp my $n_2 = Math::BigInt::FastCalc->_str($n2); is ($destroyed, 1, "_acmp($n_1,$n_2) does not leak memory"); } - diff --git a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/mbi_rand.t b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/mbi_rand.t index 4ad473d8823..1186e2e144c 100755 --- a/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/mbi_rand.t +++ b/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/t/mbi_rand.t @@ -1,55 +1,100 @@ -#!/usr/bin/perl -w +#!perl use strict; +use warnings; + use Test::More; my $count = 128; -plan(($^O eq 'os390') - ? (skip_all => 'takes too long on os390') : (tests => $count*2)); +plan(($^O eq 'os390') ? (skip_all => 'takes too long on os390') + : (tests => $count*4)); -use Math::BigInt lib => 'FastCalc'; -my $c = 'Math::BigInt'; +use Math::BigInt only => 'FastCalc'; my $length = 128; # If you get a failure here, please re-run the test with the printed seed -# value as input: perl t/mbi_rand.t seed +# value as input "perl t/mbi_rand.t seed" and send me the output + +my $seed = @ARGV == 1 ? $ARGV[0] : int(rand(1165537)); +#diag(" seed: $seed\n"); +srand($seed); + +my $_base_len; +my @_base_len; -my $seed = ($#ARGV == 0) ? $ARGV[0] : int(rand(65537)); -print "# seed: $seed\n"; srand($seed); +#diag(" lib: ", Math::BigInt->config('lib')); +if (Math::BigInt->config('lib') =~ /::Calc/) { + $_base_len = Math::BigInt::Calc->_base_len(); + @_base_len = Math::BigInt::Calc->_base_len(); + #diag("base len: $_base_len (scalar context)"); + #diag("base len: @_base_len (list contex)"); +} -my ($A,$B,$As,$Bs,$ADB,$AMB,$la,$lb); +my ($A, $B, $A_str, $B_str, $AdivB, $AmodB, $A_len, $B_len); my $two = Math::BigInt->new(2); -for (my $i = 0; $i < $count; $i++) - { - # length of A and B - $la = int(rand($length)+1); $lb = int(rand($length)+1); - $As = ''; $Bs = ''; - # we create the numbers from "patterns", e.g. get a random number and a - # random count and string them together. This means things like - # "100000999999999999911122222222" are much more likely. If we just strung - # together digits, we would end up with "1272398823211223" etc. - while (length($As) < $la) { $As .= int(rand(100)) x int(rand(16)); } - while (length($Bs) < $lb) { $Bs .= int(rand(100)) x int(rand(16)); } - $As =~ s/^0+//; $Bs =~ s/^0+//; - $As = $As || '0'; $Bs = $Bs || '0'; - # print "# As $As\n# Bs $Bs\n"; - $A = $c->new($As); $B = $c->new($Bs); - # print "# A $A\n# B $B\n"; - if ($A->is_zero() || $B->is_zero()) - { - is (1,1); is (1,1); next; +for (my $i = 0; $i < $count; $i++) { + #diag(""); + + # length of A and B + $A_len = int(rand($length) + 1); + $B_len = int(rand($length) + 1); + $A_str = ''; + $B_str = ''; + + # We create the numbers from "patterns", e.g. get a random number and a + # random count and string them together. This means things like + # "100000999999999999911122222222" are much more likely. If we just strung + # together digits, we would end up with "1272398823211223" etc. It also + # means that we get more frequently equal numbers or other special cases. + + while (length($A_str) < $A_len) { + $A_str .= int(rand(100)) x int(rand(16)); + } + while (length($B_str) < $B_len) { + $B_str .= int(rand(100)) x int(rand(16)); } - # check that int(A/B)*B + A % B == A holds for all inputs - # $X = ($A/$B)*$B + 2 * ($A % $B) - ($A % $B); - ($ADB,$AMB) = $A->copy()->bdiv($B); - print "# ". join(' ',Math::BigInt::Calc->_base_len()),"\n" - unless is ($ADB*$B+$two*$AMB-$AMB,$As); - # swap 'em and try this, too - # $X = ($B/$A)*$A + $B % $A; - ($ADB,$AMB) = $B->copy()->bdiv($A); - print "# ". join(' ',Math::BigInt::Calc->_base_len()),"\n" - unless is ($ADB*$A+$two*$AMB-$AMB,$Bs); - } + $A_str =~ s/^0+(?=\d)//; + $B_str =~ s/^0+(?=\d)//; + #diag(" As: $A_str"); + #diag(" Bs: $B_str"); + $A = Math::BigInt->new($A_str); + $B = Math::BigInt->new($B_str); + #diag(" A: $A"); + #diag(" B: $B"); + + SKIP: { + skip '$A and/or $B are zero.', 4 if $A->is_zero() || $B->is_zero(); + + # check that int(A / B) * B + A % B == A holds for all inputs + + # $X = ($A / $B) * $B + 2 * ($A % $B) - ($A % $B); + + ($AdivB, $AmodB) = $A->copy()->bdiv($B); + + #diag(" A / B: $AdivB"); + #diag(" A % B: $AmodB"); + + is($AdivB * $B + $two * $AmodB - $AmodB, $A_str, + "AdivB * B + 2 * AmodB - AmodB == A"); + + if (is($AdivB * $B / $B, $AdivB, "AdivB * B / B == AdivB")) { + if (Math::BigInt->config('lib') =~ /::Calc/) { + #diag("AdivB->[-1]: ", $AdivB->{value}->[-1]); + #diag(" B->[-1]: ", $B->{value}->[-1]); + } + } + + # swap 'em and try this, too + # $X = ($B/$A)*$A + $B % $A; + ($AdivB, $AmodB) = $B->copy()->bdiv($A); + # print "check: $AdivB $AmodB"; + + is($AdivB * $A + $two * $AmodB - $AmodB, $B_str, + "AdivB * A + 2 * AmodB - AmodB == B"); + + is($AdivB * $A / $A, $AdivB, "AdivB * A / A == AdivB"); + } +} |