diff options
author | Chris Williams <chris@bingosnet.co.uk> | 2009-09-11 10:11:50 +0100 |
---|---|---|
committer | Chris Williams <chris@bingosnet.co.uk> | 2009-09-11 10:11:50 +0100 |
commit | 94eb7880847287ea38f350b7e1f64fa31225e73a (patch) | |
tree | 331a9ce860aecb5bbafe59e15f4c7c565ce68ac5 /lib/Math/BigInt/t | |
parent | e15b45941188d3d2d63b624d6581f45a490b0b95 (diff) | |
download | perl-94eb7880847287ea38f350b7e1f64fa31225e73a.tar.gz |
Moved Math-BigInt from lib/ to ext/
Diffstat (limited to 'lib/Math/BigInt/t')
52 files changed, 0 insertions, 10501 deletions
diff --git a/lib/Math/BigInt/t/_e_math.t b/lib/Math/BigInt/t/_e_math.t deleted file mode 100644 index b3eb644437..0000000000 --- a/lib/Math/BigInt/t/_e_math.t +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/perl -w - -# test the helper math routines in Math::BigFloat - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/_e_math.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../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 => 26; - } - -use Math::BigFloat lib => 'Calc'; - -############################################################################# -# add - -my $a = Math::BigInt::Calc->_new("123"); -my $b = Math::BigInt::Calc->_new("321"); - -my ($x, $xs) = Math::BigFloat::_e_add($a,$b,'+','+'); -is (_str($x,$xs), '+444', 'add two positive numbers'); -is (_str($a,''), '444', 'a modified'); - -($x,$xs) = _add (123,321,'+','+'); -is (_str($x,$xs), '+444', 'add two positive numbers'); - -($x,$xs) = _add (123,321,'+','-'); -is (_str($x,$xs), '-198', 'add +x + -y'); -($x,$xs) = _add (123,321,'-','+'); -is (_str($x,$xs), '+198', 'add -x + +y'); - -($x,$xs) = _add (321,123,'-','+'); -is (_str($x,$xs), '-198', 'add -x + +y'); -($x,$xs) = _add (321,123,'+','-'); -is (_str($x,$xs), '+198', 'add +x + -y'); - -($x,$xs) = _add (10,1,'+','-'); -is (_str($x,$xs), '+9', 'add 10 + -1'); -($x,$xs) = _add (10,1,'-','+'); -is (_str($x,$xs), '-9', 'add -10 + +1'); -($x,$xs) = _add (1,10,'-','+'); -is (_str($x,$xs), '+9', 'add -1 + 10'); -($x,$xs) = _add (1,10,'+','-'); -is (_str($x,$xs), '-9', 'add 1 + -10'); - -############################################################################# -# sub - -$a = Math::BigInt::Calc->_new("123"); -$b = Math::BigInt::Calc->_new("321"); -($x, $xs) = Math::BigFloat::_e_sub($b,$a,'+','+'); -is (_str($x,$xs), '+198', 'sub two positive numbers'); -is (_str($b,''), '198', 'a modified'); - -($x,$xs) = _sub (123,321,'+','-'); -is (_str($x,$xs), '+444', 'sub +x + -y'); -($x,$xs) = _sub (123,321,'-','+'); -is (_str($x,$xs), '-444', 'sub -x + +y'); - -sub _add - { - my ($a,$b,$as,$bs) = @_; - - my $aa = Math::BigInt::Calc->_new($a); - my $bb = Math::BigInt::Calc->_new($b); - my ($x, $xs) = Math::BigFloat::_e_add($aa,$bb,$as,$bs); - is (Math::BigInt::Calc->_str($x), Math::BigInt::Calc->_str($aa), - 'param0 modified'); - ($x,$xs); - } - -sub _sub - { - my ($a,$b,$as,$bs) = @_; - - my $aa = Math::BigInt::Calc->_new($a); - my $bb = Math::BigInt::Calc->_new($b); - my ($x, $xs) = Math::BigFloat::_e_sub($aa,$bb,$as,$bs); - is (Math::BigInt::Calc->_str($x), Math::BigInt::Calc->_str($aa), - 'param0 modified'); - ($x,$xs); - } - -sub _str - { - my ($x,$s) = @_; - - $s . Math::BigInt::Calc->_str($x); - } diff --git a/lib/Math/BigInt/t/alias.inc b/lib/Math/BigInt/t/alias.inc deleted file mode 100644 index 746a20c99e..0000000000 --- a/lib/Math/BigInt/t/alias.inc +++ /dev/null @@ -1,12 +0,0 @@ - -# alias subroutine testing, included by sub_ali.t and mbi_ali.t - -my $x = $CL->new(123); - -is ($x->is_pos(), 1, '123 is positive'); -is ($x->is_neg(), 0, '123 is not negative'); -is ($x->as_int(), 123, '123 is 123 as int'); -is (ref($x->as_int()), 'Math::BigInt', "as_int(123) is of class Math::BigInt"); -$x->bneg(); -is ($x->is_pos(), 0, '-123 is not positive'); -is ($x->is_neg(), 1, '-123 is negative'); diff --git a/lib/Math/BigInt/t/bare_mbf.t b/lib/Math/BigInt/t/bare_mbf.t deleted file mode 100644 index 9bb4bcea5f..0000000000 --- a/lib/Math/BigInt/t/bare_mbf.t +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bare_mbf.t//i; - print "# $0\n"; - 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 => 2308; - } - -use Math::BigFloat lib => 'BareCalc'; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigFloat"; -$CL = "Math::BigInt::BareCalc"; - -require 'bigfltpm.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/bare_mbi.t b/lib/Math/BigInt/t/bare_mbi.t deleted file mode 100644 index 637e695b69..0000000000 --- a/lib/Math/BigInt/t/bare_mbi.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bare_mbi.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 3273; - } - -use Math::BigInt lib => 'BareCalc'; - -print "# ",Math::BigInt->config()->{lib},"\n"; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigInt"; -$CL = "Math::BigInt::BareCalc"; - -my $version = '1.84'; # for $VERSION tests, match current release (by hand!) - -require 'bigintpm.inc'; # perform same tests as bigintpm - diff --git a/lib/Math/BigInt/t/bare_mif.t b/lib/Math/BigInt/t/bare_mif.t deleted file mode 100644 index 0cc1de9365..0000000000 --- a/lib/Math/BigInt/t/bare_mif.t +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl -w - -# test rounding, accuracy, precicion and fallback, round_mode and mixing -# of classes under BareCalc - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bare_mif.t//i; - if ($ENV{PERL_CORE}) - { - @INC = qw(../t/lib); # testing with the core distribution - } - unshift @INC, '../lib'; # for testing manually - 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 => 684 - + 1; # our own tests - } - -print "# ",Math::BigInt->config()->{lib},"\n"; - -use Math::BigInt lib => 'BareCalc'; -use Math::BigFloat lib => 'BareCalc'; - -use vars qw/$mbi $mbf/; - -$mbi = 'Math::BigInt'; -$mbf = 'Math::BigFloat'; - -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -require 'mbimbf.inc'; - diff --git a/lib/Math/BigInt/t/big_pi_e.t b/lib/Math/BigInt/t/big_pi_e.t deleted file mode 100644 index 9ecae00dcc..0000000000 --- a/lib/Math/BigInt/t/big_pi_e.t +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/perl -w - -# Test bpi() and bexp() - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/big_pi_e.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../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 => 8; - } - -use Math::BigFloat; - -############################################################################# - -my $pi = Math::BigFloat::bpi(); - -ok (!exists $pi->{_a}, 'A not set'); -ok (!exists $pi->{_p}, 'P not set'); - -$pi = Math::BigFloat->bpi(); - -ok (!exists $pi->{_a}, 'A not set'); -ok (!exists $pi->{_p}, 'P not set'); - -$pi = Math::BigFloat->bpi(10); - -is ($pi->{_a}, 10, 'A set'); -is ($pi->{_p}, undef, 'P not set'); - -############################################################################# -my $e = Math::BigFloat->new(1)->bexp(); - -ok (!exists $e->{_a}, 'A not set'); -ok (!exists $e->{_p}, 'P not set'); - - diff --git a/lib/Math/BigInt/t/bigfltpm.inc b/lib/Math/BigInt/t/bigfltpm.inc deleted file mode 100644 index 7d650e5cba..0000000000 --- a/lib/Math/BigInt/t/bigfltpm.inc +++ /dev/null @@ -1,1823 +0,0 @@ -#include this file into another test for subclass testing... - -ok ($class->config()->{lib},$CL); - -use strict; - -my $z; - -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - $_ =~ s/#.*$//; # remove comments - $_ =~ s/\s+$//; # trailing spaces - next if /^$/; # skip empty lines & comments - if (s/^&//) - { - $f = $_; - } - elsif (/^\$/) - { - $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale - #print "\$setup== $setup\n"; - } - else - { - if (m|^(.*?):(/.+)$|) - { - $ans = $2; - @args = split(/:/,$1,99); - } - else - { - @args = split(/:/,$_,99); $ans = pop(@args); - } - $try = "\$x = $class->new(\"$args[0]\");"; - if ($f eq "fnorm") - { - $try .= "\$x;"; - } elsif ($f eq "finf") { - $try .= "\$x->finf('$args[1]');"; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "fone") { - $try .= "\$x->bone('$args[1]');"; - } elsif ($f eq "fstr") { - $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);"; - $try .= '$x->fstr();'; - } elsif ($f eq "parts") { - # ->bstr() to see if an object is returned - $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; - $try .= '"$a $b";'; - } elsif ($f eq "exponent") { - # ->bstr() to see if an object is returned - $try .= '$x->exponent()->bstr();'; - } elsif ($f eq "mantissa") { - # ->bstr() to see if an object is returned - $try .= '$x->mantissa()->bstr();'; - } elsif ($f =~ /^(numify|length|as_number|as_hex|as_bin)$/) { - $try .= "\$x->$f();"; - # some unary ops (test the fxxx form, since that is done by AUTOLOAD) - } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { - $try .= "\$x->f$1();"; - # some is_xxx test function - } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "bpi") { - $try .= '$class->bpi($x);'; - } elsif ($f eq "finc") { - $try .= '++$x;'; - } elsif ($f eq "fdec") { - $try .= '--$x;'; - }elsif ($f eq "fround") { - $try .= "$setup; \$x->fround($args[1]);"; - } elsif ($f eq "ffround") { - $try .= "$setup; \$x->ffround($args[1]);"; - } elsif ($f eq "fsqrt") { - $try .= "$setup; \$x->fsqrt();"; - } elsif ($f eq "ffac") { - $try .= "$setup; \$x->ffac();"; - } elsif ($f eq "flog") { - if (defined $args[1] && $args[1] ne '') - { - $try .= "\$y = $class->new($args[1]);"; - $try .= "$setup; \$x->flog(\$y);"; - } - else - { - $try .= "$setup; \$x->flog();"; - } - } - else - { - $try .= "\$y = $class->new(\"$args[1]\");"; - - 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->fcmp($y);'; - } elsif ($f eq "facmp") { - $try .= '$x->facmp($y);'; - } elsif ($f eq "fpow") { - $try .= '$x ** $y;'; - } elsif ($f eq "bnok") { - $try .= '$x->bnok($y);'; - } elsif ($f eq "bcos") { - $try .= '$x->bcos($y);'; - } elsif ($f eq "bsin") { - $try .= '$x->bsin($y);'; - } elsif ($f eq "batan") { - $try .= '$x->batan($y);'; - } elsif ($f eq "froot") { - $try .= "$setup; \$x->froot(\$y);"; - } elsif ($f eq "fadd") { - $try .= '$x + $y;'; - } elsif ($f eq "fsub") { - $try .= '$x - $y;'; - } elsif ($f eq "fmul") { - $try .= '$x * $y;'; - } elsif ($f eq "fdiv") { - $try .= "$setup; \$x / \$y;"; - } elsif ($f eq "fdiv-list") { - $try .= "$setup; join(',',\$x->fdiv(\$y));"; - } elsif ($f eq "frsft") { - $try .= '$x >> $y;'; - } elsif ($f eq "flsft") { - $try .= '$x << $y;'; - } elsif ($f eq "fmod") { - $try .= '$x % $y;'; - } else { - # Functions with three arguments - $try .= "\$z = $class->new(\"$args[2]\");"; - - if( $f eq "bmodpow") { - $try .= '$x->bmodpow($y,$z);'; - } elsif ($f eq "bmuladd"){ - $try .= '$x->bmuladd($y,$z);'; - } elsif ($f eq "batan2"){ - $try .= '$x->batan2($y,$z);'; - } else { warn "Unknown op '$f'"; } - } - } - # print "# Trying: '$try'\n"; - $ans1 = eval $try; - print "# Error: $@\n" if $@; - if ($ans =~ m|^/(.*)$|) - { - my $pat = $1; - if ($ans1 =~ /$pat/) - { - ok (1,1); - } - else - { - print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0); - } - } - else - { - if ($ans eq "") - { - ok_undef ($ans1); - } - else - { - print "# Tried: '$try'\n" if !ok ($ans1, $ans); - if (ref($ans1) eq "$class") - { - # float numbers are normalized (for now), so mantissa shouldn't have - # trailing zeros - #print $ans1->_trailing_zeros(),"\n"; - print "# Has trailing zeros after '$try'\n" - if !ok ($CL->_zeros( $ans1->{_m}), 0); - } - } - } # end pattern or string - } - } # end while - -# check whether $class->new( Math::BigInt->new()) destroys it -# ($y == 12 in this case) -$x = Math::BigInt->new(1200); $y = $class->new($x); -ok ($y,1200); ok ($x,1200); - -############################################################################### -# Really huge, big, ultra-mega-biggy-monster exponents -# Technically, the exponents should not be limited (they are BigInts), but -# practically there are a few places were they are limited to a Perl scalar. -# This is sometimes for speed, sometimes because otherwise the number wouldn't -# fit into your memory (just think of 1e123456789012345678901234567890 + 1!) -# anyway. We don't test everything here, but let's make sure it just basically -# works. - -my $monster = '1e1234567890123456789012345678901234567890'; - -# new and exponent -ok ($class->new($monster)->bsstr(), - '1e+1234567890123456789012345678901234567890'); -ok ($class->new($monster)->exponent(), - '1234567890123456789012345678901234567890'); -# cmp -ok ($class->new($monster) > 0,1); - -# sub/mul -ok ($class->new($monster)->bsub( $monster),0); -ok ($class->new($monster)->bmul(2)->bsstr(), - '2e+1234567890123456789012345678901234567890'); - -# mantissa -$monster = '1234567890123456789012345678901234567890e2'; -ok ($class->new($monster)->mantissa(), - '123456789012345678901234567890123456789'); - -############################################################################### -# zero,inf,one,nan - -$x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - -############################################################################### -# bone/binf etc as plain calls (Lite failed them) - -ok ($class->fzero(),0); -ok ($class->fone(),1); -ok ($class->fone('+'),1); -ok ($class->fone('-'),-1); -ok ($class->fnan(),'NaN'); -ok ($class->finf(),'inf'); -ok ($class->finf('+'),'inf'); -ok ($class->finf('-'),'-inf'); -ok ($class->finf('-inf'),'-inf'); - -$class->accuracy(undef); $class->precision(undef); # reset - -############################################################################### -# bug in bsstr()/numify() showed up in after-rounding in bdiv() - -$x = $class->new('0.008'); $y = $class->new(2); -$x->bdiv(3,$y); -ok ($x,'0.0027'); - -############################################################################### -# fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt() -# correctly modifies $x - - -$x = $class->new(12); $class->precision(-2); $x->fsqrt(); ok ($x,'3.46'); - -$class->precision(undef); -$x = $class->new(12); $class->precision(0); $x->fsqrt(); ok ($x,'3'); - -$class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464'); - -{ - no strict 'refs'; - # A and P set => NaN - ${${class}.'::accuracy'} = 4; $x = $class->new(12); - $x->fsqrt(3); ok ($x,'NaN'); - # supplied arg overrides set global - $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); ok ($x,'3.46'); - $class->accuracy(undef); $class->precision(undef); # reset for further tests -} - -############################################################################# -# can we call objectify (broken until v1.52) - -{ - no strict; - $try = - '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);'; - $ans = eval $try; - ok ($ans,"$class 4 5"); -} - -############################################################################# -# is_one('-') (broken until v1.64) - -ok ($class->new(-1)->is_one(),0); -ok ($class->new(-1)->is_one('-'),1); - -############################################################################# -# bug 1/0.5 leaving 2e-0 instead of 2e0 - -ok ($class->new(1)->fdiv('0.5')->bsstr(),'2e+0'); - -############################################################################### -# [perl #30609] bug with $x -= $x not being 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(3); $x += $x; ok ($x, 6); -$x = $class->new(-3); $x += $x; ok ($x, -6); - -$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.14'); $x -= $x; ok ($x, 0); -$x = $class->new('-3.14'); $x -= $x; ok ($x, 0); -$x = $class->new('3.14'); $x += $x; ok ($x, '6.28'); -$x = $class->new('-3.14'); $x += $x; ok ($x, '-6.28'); - -$x = $class->new('3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('-3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('-3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('3.14'); $x %= $x; ok ($x, '0'); -$x = $class->new('-3.14'); $x %= $x; ok ($x, '0'); - -############################################################################### -# the following two were reported by "kenny" via hotmail.com: - -#perl -MMath::BigFloat -wle 'print Math::BigFloat->new(0)->bpow(".1")' -#Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. - -$x = $class->new(0); $y = $class->new('0.1'); -ok ($x ** $y, 0, 'no warnings and zero result'); - -#perl -MMath::BigFloat -lwe 'print Math::BigFloat->new(".222222222222222222222222222222222222222222")->bceil()' -#Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. - -$x = $class->new(".222222222222222222222222222222222222222222"); -ok ($x->bceil(), 1, 'no warnings and one as result'); - -############################################################################### -# test **=, <<=, >>= - -# ((2^148)-1)/17 -$x = $class->new(2); $x **= 148; $x++; $x->bdiv(17, 60)->bfloor(); $x->accuracy(undef); -ok ($x,"20988936657440586486151264256610222593863921"); -ok ($x->length(),length "20988936657440586486151264256610222593863921"); - -$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); - -$x = $class->new('2'); -$y = $class->new('18.2'); -$x <<= $y; # 2 * (2 ** 18.2); - -ok ($x->copy()->bfround(-9), '602248.763144685'); -ok ($x >>= $y, 2); # 2 * (2 ** 18.2) / (2 ** 18.2) => 2 -ok ($x, 2); - -1; # all done - -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return if !defined $x; - ok ($x,'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; -&bcos -1.2:10:0.3623577545 -2.4:12:-0.737393715541 -0:10:1 -0:20:1 -1:10:0.5403023059 -1:12:0.540302305868 -&bsin -1:10:0.8414709848 -0:10:0 -0:20:0 -2.1:12:0.863209366649 -1.2:13:0.9320390859672 -0.2:13:0.1986693307951 -3.2:12:-0.0583741434276 -&batan -NaN:10:NaN -inf:14:1.5707963267949 --inf:14:-1.5707963267949 -0.2:13:0.1973955598499 -0.2:14:0.19739555984988 -0:10:0 -1:14:0.78539816339744 --1:14:-0.78539816339744 -# test an argument X > 1 -2:14:1.1071487177941 -&batan2 -NaN:1:10:NaN -NaN:NaN:10:NaN -1:NaN:10:NaN -inf:1:14:1.5707963267949 --inf:1:14:-1.5707963267949 -0:-inf:14:3.1415926535898 --1:-inf:14:-3.1415926535898 -1:-inf:14:3.1415926535898 -0:inf:14:0 -inf:-inf:14:2.3561944901923 --inf:-inf:14:-2.3561944901923 -inf:+inf:14:0.7853981633974 --inf:+inf:14:-0.7853981633974 -1:5:13:0.1973955598499 -1:5:14:0.19739555984988 -0:0:10:0 -0:1:14:0 -0:2:14:0 -1:0:14:1.5707963267949 -5:0:14:1.5707963267949 --1:0:11:-1.5707963268 --2:0:77:-1.5707963267948966192313216916397514420985846996875529104874722961539082031431 -2:0:77:1.5707963267948966192313216916397514420985846996875529104874722961539082031431 --1:5:14:-0.19739555984988 -1:5:14:0.19739555984988 --1:8:14:-0.12435499454676 -1:8:14:0.12435499454676 --1:1:14:-0.78539816339744 -# test an argument X > 1 and one X < 1 -1:2:24:0.463647609000806116214256 -2:1:14:1.1071487177941 --2:1:14:-1.1071487177941 -&bpi -150:3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940813 -77:3.1415926535897932384626433832795028841971693993751058209749445923078164062862 -+0:3.141592653589793238462643383279502884197 -11:3.1415926536 -&bnok -+inf:10:inf -NaN:NaN:NaN -NaN:1:NaN -1:NaN:NaN -1:1:1 -# k > n -1:2:0 -2:3:0 -# k < 0 -1:-2:0 -# 7 over 3 = 35 -7:3:35 -7:6:1 -100:90:17310309456440 -&flog -0::NaN --1::NaN --2::NaN -# base > 0, base != 1 -2:-1:NaN -2:0:NaN -2:1:NaN -# log(1) is always 1, regardless of $base -1::0 -1:1:0 -1:2:0 -2::0.6931471805599453094172321214581765680755 -2.718281828::0.9999999998311266953289851340574956564911 -$div_scale = 20; -2.718281828::0.99999999983112669533 -$div_scale = 15; -123::4.81218435537242 -10::2.30258509299405 -1000::6.90775527898214 -100::4.60517018598809 -2::0.693147180559945 -3.1415::1.14470039286086 -12345::9.42100640177928 -0.001::-6.90775527898214 -# bug until v1.71: -10:10:1 -100:100:1 -# reset for further tests -$div_scale = 40; -1::0 -&frsft -NaNfrsft:2:NaN -0:2:0 -1:1:0.5 -2:1:1 -4:1:2 -123:1:61.5 -32:3:4 -&flsft -NaNflsft:0:NaN -2:1:4 -4:3:32 -5:3:40 -1:2:4 -0:5:0 -&fnorm -1:1 --0:0 -fnormNaN:NaN -+inf:inf --inf:-inf -123:123 --123.4567:-123.4567 -# invalid inputs -1__2:NaN -1E1__2:NaN -11__2E2:NaN -.2E-3.:NaN -1e3e4:NaN -# strange, but valid -.2E2:20 -1.E3:1000 -# 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 -&as_number -0:0 -1:1 -1.2:1 -2.345:2 --2:-2 --123.456:-123 --200:-200 -# test for bug in brsft() not handling cases that return 0 -0.000641:0 -0.0006412:0 -0.00064123:0 -0.000641234:0 -0.0006412345:0 -0.00064123456:0 -0.000641234567:0 -0.0006412345678:0 -0.00064123456789:0 -0.1:0 -0.01:0 -0.001:0 -0.0001:0 -0.00001:0 -0.000001:0 -0.0000001:0 -0.00000001:0 -0.000000001:0 -0.0000000001:0 -0.00000000001:0 -0.12345:0 -0.123456:0 -0.1234567:0 -0.12345678:0 -0.123456789:0 -&finf -1:+:inf -2:-:-inf -3:abc:inf -&as_hex -+inf:inf --inf:-inf -hexNaN:NaN -0:0x0 -5:0x5 --5:-0x5 -&as_bin -+inf:inf --inf:-inf -hexNaN:NaN -0:0b0 -5:0b101 --5:-0b101 -&numify -# uses bsstr() so 5 => 5e+0 to be compatible w/ Perls output -0:0e+1 -+1:1e+0 -1234:1234e+0 -NaN:NaN -+inf:inf --inf:-inf --5:-5e+0 -100:1e+2 --100:-1e+2 -&fnan -abc:NaN -2:NaN --2:NaN -0:NaN -&fone -2:+:1 --2:-:-1 --2:+:1 -2:-:-1 -0::1 --2::1 -abc::1 -2:abc:1 -&fsstr -+inf:inf --inf:-inf -abcfsstr:NaN --abcfsstr:NaN -1234.567:1234567e-3 -123:123e+0 --5:-5e+0 --100:-1e+2 -&fstr -+inf:::inf --inf:::-inf -abcfstr:::NaN -1234.567:9::1234.56700 -1234.567::-6:1234.567000 -12345:5::12345 -0.001234:6::0.00123400 -0.001234::-8:0.00123400 -0:4::0 -0::-4:0.0000 -&fnorm -inf:inf -+inf:inf --inf:-inf -+infinity:NaN -+-inf:NaN -abc:NaN - 1 a:NaN -1bcd2:NaN -11111b:NaN -+1z:NaN --1z:NaN -0e999:0 -0e-999:0 --0e999:0 --0e-999:0 -0:0 -+0:0 -+00:0 -+0_0_0:0 -000000_0000000_00000:0 --0:0 --0000:0 -+1:1 -+01:1 -+001:1 -+00000100000:100000 -123456789:123456789 --1:-1 --01:-1 --001:-1 --123456789:-123456789 --00000100000:-100000 -123.456a:NaN -123.456:123.456 -0.01:0.01 -.002:0.002 -+.2:0.2 --0.0003:-0.0003 --.0000000004:-0.0000000004 -123456E2:12345600 -123456E-2:1234.56 --123456E2:-12345600 --123456E-2:-1234.56 -1e1:10 -2e-11:0.00000000002 -# excercise _split - .02e-1:0.002 - 000001:1 - -00001:-1 - -1:-1 - 000.01:0.01 - -000.0023:-0.0023 - 1.1e1:11 --3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 --4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 -&fpow -NaN:1:NaN -1:NaN:NaN -NaN:-1:NaN --1:NaN:NaN -NaN:-21:NaN --21:NaN:NaN -NaN:21:NaN -21:NaN:NaN -0:0:1 -0:1:0 -0:9:0 -0:-2:inf -2:2:4 -1:2:1 -1:3:1 --1:2:1 --1:3:-1 -123.456:2:15241.383936 -2:-2:0.25 -2:-3:0.125 -128:-2:0.00006103515625 -abc:123.456:NaN -123.456:abc:NaN -+inf:123.45:inf --inf:123.45:-inf -+inf:-123.45:inf --inf:-123.45:-inf --2:2:4 --2:3:-8 --2:4:16 --2:5:-32 --3:2:9 --3:3:-27 --3:4:81 --3:5:-243 -# 2 ** 0.5 == sqrt(2) -# 1.41..7 and not 1.4170 since fallback (bsqrt(9) is '3', not 3.0...0) -2:0.5:1.41421356237309504880168872420969807857 -#2:0.2:1.148698354997035006798626946777927589444 -#6:1.5:14.6969384566990685891837044482353483518 -$div_scale = 20; -#62.5:12.5:26447206647554886213592.3959144 -$div_scale = 40; -&fneg -fnegNaN:NaN -+inf:-inf --inf:inf -+0:0 -+1:-1 --1:1 -+123456789:-123456789 --123456789:123456789 -+123.456789:-123.456789 --123456.789:123456.789 -&fabs -fabsNaN:NaN -+inf:inf --inf:inf -+0:0 -+1:1 --1:1 -+123456789:123456789 --123456789:123456789 -+123.456789:123.456789 --123456.789:123456.789 -&fround -$round_mode = "trunc" -+inf:5:inf --inf:5:-inf -0:5:0 -NaNfround:5:NaN -+10123456789:5:10123000000 --10123456789:5:-10123000000 -+10123456789.123:5:10123000000 --10123456789.123:5:-10123000000 -+10123456789:9:10123456700 --10123456789:9:-10123456700 -+101234500:6:101234000 --101234500:6:-101234000 -$round_mode = "zero" -+20123456789:5:20123000000 --20123456789:5:-20123000000 -+20123456789.123:5:20123000000 --20123456789.123:5:-20123000000 -+20123456789:9:20123456800 --20123456789:9:-20123456800 -+201234500:6:201234000 --201234500:6:-201234000 -$round_mode = "+inf" -+30123456789:5:30123000000 --30123456789:5:-30123000000 -+30123456789.123:5:30123000000 --30123456789.123:5:-30123000000 -+30123456789:9:30123456800 --30123456789:9:-30123456800 -+301234500:6:301235000 --301234500:6:-301234000 -$round_mode = "-inf" -+40123456789:5:40123000000 --40123456789:5:-40123000000 -+40123456789.123:5:40123000000 --40123456789.123:5:-40123000000 -+40123456789:9:40123456800 --40123456789:9:-40123456800 -+401234500:6:401234000 --401234500:6:-401235000 -$round_mode = "odd" -+50123456789:5:50123000000 --50123456789:5:-50123000000 -+50123456789.123:5:50123000000 --50123456789.123:5:-50123000000 -+50123456789:9:50123456800 --50123456789:9:-50123456800 -+501234500:6:501235000 --501234500:6:-501235000 -$round_mode = "even" -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601234000 --601234500:6:-601234000 -+60123456789.0123:5:60123000000 --60123456789.0123:5:-60123000000 -$round_mode = "common" -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:6:60123500000 --60123456789:6:-60123500000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601235000 --601234500:6:-601235000 -+601234400:6:601234000 --601234400:6:-601234000 -+601234600:6:601235000 --601234600:6:-601235000 -+601234300:6:601234000 -+60123456789.0123:5:60123000000 --60123456789.0123:5:-60123000000 -&ffround -$round_mode = "trunc" -+inf:5:inf --inf:5:-inf -0:5:0 -NaNffround:5:NaN -+1.23:-1:1.2 -+1.234:-1:1.2 -+1.2345:-1:1.2 -+1.23:-2:1.23 -+1.234:-2:1.23 -+1.2345:-2:1.23 -+1.23:-3:1.230 -+1.234:-3:1.234 -+1.2345:-3:1.234 --1.23:-1:-1.2 -+1.27:-1:1.2 --1.27:-1:-1.2 -+1.25:-1:1.2 --1.25:-1:-1.2 -+1.35:-1:1.3 --1.35:-1:-1.3 --0.0061234567890:-1:0.0 --0.0061:-1:0.0 --0.00612:-1:0.0 --0.00612:-2:0.00 --0.006:-1:0.0 --0.006:-2:0.00 --0.0006:-2:0.00 --0.0006:-3:0.000 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:0 -0.41:0:0 -$round_mode = "zero" -+2.23:-1:/2.2(?:0{5}\d+)? --2.23:-1:/-2.2(?:0{5}\d+)? -+2.27:-1:/2.(?:3|29{5}\d+) --2.27:-1:/-2.(?:3|29{5}\d+) -+2.25:-1:/2.2(?:0{5}\d+)? --2.25:-1:/-2.2(?:0{5}\d+)? -+2.35:-1:/2.(?:3|29{5}\d+) --2.35:-1:/-2.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -$round_mode = "+inf" -+3.23:-1:/3.2(?:0{5}\d+)? --3.23:-1:/-3.2(?:0{5}\d+)? -+3.27:-1:/3.(?:3|29{5}\d+) --3.27:-1:/-3.(?:3|29{5}\d+) -+3.25:-1:/3.(?:3|29{5}\d+) --3.25:-1:/-3.2(?:0{5}\d+)? -+3.35:-1:/3.(?:4|39{5}\d+) --3.35:-1:/-3.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:1 -0.51:0:1 -0.41:0:0 -$round_mode = "-inf" -+4.23:-1:/4.2(?:0{5}\d+)? --4.23:-1:/-4.2(?:0{5}\d+)? -+4.27:-1:/4.(?:3|29{5}\d+) --4.27:-1:/-4.(?:3|29{5}\d+) -+4.25:-1:/4.2(?:0{5}\d+)? --4.25:-1:/-4.(?:3|29{5}\d+) -+4.35:-1:/4.(?:3|29{5}\d+) --4.35:-1:/-4.(?:4|39{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.007|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -$round_mode = "odd" -+5.23:-1:/5.2(?:0{5}\d+)? --5.23:-1:/-5.2(?:0{5}\d+)? -+5.27:-1:/5.(?:3|29{5}\d+) --5.27:-1:/-5.(?:3|29{5}\d+) -+5.25:-1:/5.(?:3|29{5}\d+) --5.25:-1:/-5.(?:3|29{5}\d+) -+5.35:-1:/5.(?:3|29{5}\d+) --5.35:-1:/-5.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.007|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:1 -0.51:0:1 -0.41:0:0 -$round_mode = "even" -+6.23:-1:/6.2(?:0{5}\d+)? --6.23:-1:/-6.2(?:0{5}\d+)? -+6.27:-1:/6.(?:3|29{5}\d+) --6.27:-1:/-6.(?:3|29{5}\d+) -+6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+) --6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+) -+6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+) --6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -0.01234567:-3:0.012 -0.01234567:-4:0.0123 -0.01234567:-5:0.01235 -0.01234567:-6:0.012346 -0.01234567:-7:0.0123457 -0.01234567:-8:0.01234567 -0.01234567:-9:0.012345670 -0.01234567:-12:0.012345670000 -&fcmp -fcmpNaN:fcmpNaN: -fcmpNaN:+0: -+0:fcmpNaN: -+0:+0:0 --1:+0:-1 -+0:-1:1 -+1:+0:1 -+0:+1:-1 --1:+1:-1 -+1:-1:1 --1:-1:0 -+1:+1:0 --1.1:0:-1 -+0:-1.1:1 -+1.1:+0:1 -+0:+1.1:-1 -+123:+123:0 -+123:+12:1 -+12:+123:-1 --123:-123:0 --123:-12:-1 --12:-123:1 -+123:+124:-1 -+124:+123:1 --123:-124:1 --124:-123:-1 -0:0.01:-1 -0:0.0001:-1 -0:-0.0001:1 -0:-0.1:1 -0.1:0:1 -0.00001:0:1 --0.0001:0:-1 --0.1:0:-1 -0:0.0001234:-1 -0:-0.0001234:1 -0.0001234:0:1 --0.0001234:0:-1 -0.0001:0.0005:-1 -0.0005:0.0001:1 -0.005:0.0001:1 -0.001:0.0005:1 -0.000001:0.0005:-1 -0.00000123:0.0005:-1 -0.00512:0.0001:1 -0.005:0.000112:1 -0.00123:0.0005:1 -1.5:2:-1 -2:1.5:1 -1.54321:234:-1 -234:1.54321:1 -# infinity --inf:5432112345:-1 -+inf:5432112345:1 --inf:-5432112345:-1 -+inf:-5432112345:1 --inf:54321.12345:-1 -+inf:54321.12345:1 --inf:-54321.12345:-1 -+inf:-54321.12345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:1 --inf:+inf:-1 -# return undef -+inf:NaN: -NaN:inf: --inf:NaN: -NaN:-inf: -&facmp -fcmpNaN:fcmpNaN: -fcmpNaN:+0: -+0:fcmpNaN: -+0:+0:0 --1:+0:1 -+0:-1:-1 -+1:+0:1 -+0:+1:-1 --1:+1:0 -+1:-1:0 --1:-1:0 -+1:+1:0 --1.1:0:1 -+0:-1.1:-1 -+1.1:+0:1 -+0:+1.1:-1 -+123:+123:0 -+123:+12:1 -+12:+123:-1 --123:-123:0 --123:-12:1 --12:-123:-1 -+123:+124:-1 -+124:+123:1 --123:-124:-1 --124:-123:1 -0:0.01:-1 -0:0.0001:-1 -0:-0.0001:-1 -0:-0.1:-1 -0.1:0:1 -0.00001:0:1 --0.0001:0:1 --0.1:0:1 -0:0.0001234:-1 -0:-0.0001234:-1 -0.0001234:0:1 --0.0001234:0:1 -0.0001:0.0005:-1 -0.0005:0.0001:1 -0.005:0.0001:1 -0.001:0.0005:1 -0.000001:0.0005:-1 -0.00000123:0.0005:-1 -0.00512:0.0001:1 -0.005:0.000112:1 -0.00123:0.0005:1 -1.5:2:-1 -2:1.5:1 -1.54321:234:-1 -234:1.54321:1 -# infinity --inf:5432112345:1 -+inf:5432112345:1 --inf:-5432112345:1 -+inf:-5432112345:1 --inf:54321.12345:1 -+inf:54321.12345:1 --inf:-54321.12345:1 -+inf:-54321.12345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:0 --inf:+inf:0 -5:inf:-1 --1:inf:-1 -5:-inf:-1 --1:-inf:-1 -# return undef -+inf:facmpNaN: -facmpNaN:inf: --inf:facmpNaN: -facmpNaN:-inf: -&fdec -fdecNaN:NaN -+inf:inf --inf:-inf -+0:-1 -+1:0 --1:-2 -1.23:0.23 --1.23:-2.23 -100:99 -101:100 --100:-101 --99:-100 --98:-99 -99:98 -&finc -fincNaN:NaN -+inf:inf --inf:-inf -+0:1 -+1:2 --1:0 -1.23:2.23 --1.23:-0.23 -100:101 --100:-99 --99:-98 --101:-100 -99:100 -&fadd -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:NaN --inf:+inf:NaN -+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 -+1:+1:2 --1:+0:-1 -+0:-1:-1 --1:-1:-2 --1:+1:0 -+1:-1:0 -+9:+1:10 -+99:+1:100 -+999:+1:1000 -+9999:+1:10000 -+99999:+1:100000 -+999999:+1:1000000 -+9999999:+1:10000000 -+99999999:+1:100000000 -+999999999:+1:1000000000 -+9999999999:+1:10000000000 -+99999999999:+1:100000000000 -+10:-1:9 -+100:-1:99 -+1000:-1:999 -+10000:-1:9999 -+100000:-1:99999 -+1000000:-1:999999 -+10000000:-1:9999999 -+100000000:-1:99999999 -+1000000000:-1:999999999 -+10000000000:-1:9999999999 -+123456789:+987654321:1111111110 --123456789:+987654321:864197532 --123456789:-987654321:-1111111110 -+123456789:-987654321:-864197532 -0.001234:0.0001234:0.0013574 -&fsub -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:inf --inf:+inf:-inf -+inf:+inf:NaN --inf:-inf:NaN -baddNaN:+inf:NaN -baddNaN:+inf:NaN -+inf:baddNaN:NaN --inf:baddNaN:NaN -+0:+0:0 -+1:+0:1 -+0:+1:-1 -+1:+1:0 --1:+0:-1 -+0:-1:1 --1:-1:0 --1:+1:-2 -+1:-1:2 -+9:+1:8 -+99:+1:98 -+999:+1:998 -+9999:+1:9998 -+99999:+1:99998 -+999999:+1:999998 -+9999999:+1:9999998 -+99999999:+1:99999998 -+999999999:+1:999999998 -+9999999999:+1:9999999998 -+99999999999:+1:99999999998 -+10:-1:11 -+100:-1:101 -+1000:-1:1001 -+10000:-1:10001 -+100000:-1:100001 -+1000000:-1:1000001 -+10000000:-1:10000001 -+100000000:-1:100000001 -+1000000000:-1:1000000001 -+10000000000:-1:10000000001 -+123456789:+987654321:-864197532 --123456789:+987654321:-1111111110 --123456789:-987654321:864197532 -+123456789:-987654321:1111111110 -&bmuladd -abc:abc:0:NaN -abc:+0:0:NaN -+0:abc:0:NaN -+0:0:abc:NaN -NaNmul:+inf:0:NaN -NaNmul:-inf:0:NaN --inf:NaNmul:0:NaN -+inf:NaNmul:0:NaN -+inf:+inf:0:inf -+inf:-inf:0:-inf --inf:+inf:0:-inf --inf:-inf:0:inf -+0:+0:0:0 -+0:+1:0:0 -+1:+0:0:0 -+0:-1:0:0 --1:+0:0:0 -123456789123456789:0:0:0 -0:123456789123456789:0:0 --1:-1:0:1 --1:-1:0:1 --1:+1:0:-1 -+1:-1:0:-1 -+1:+1:0:1 -+2:+3:0:6 --2:+3:0:-6 -+2:-3:0:-6 --2:-3:0:6 -111:111:0:12321 -10101:10101:0:102030201 -1001001:1001001:0:1002003002001 -100010001:100010001:0:10002000300020001 -10000100001:10000100001:0:100002000030000200001 -11111111111:9:0:99999999999 -22222222222:9:0:199999999998 -33333333333:9:0:299999999997 -44444444444:9:0:399999999996 -55555555555:9:0:499999999995 -66666666666:9:0:599999999994 -77777777777:9:0:699999999993 -88888888888:9:0:799999999992 -99999999999:9:0:899999999991 -11111111111:9:1:100000000000 -22222222222:9:1:199999999999 -33333333333:9:1:299999999998 -44444444444:9:1:399999999997 -55555555555:9:1:499999999996 -66666666666:9:1:599999999995 -77777777777:9:1:699999999994 -88888888888:9:1:799999999993 -99999999999:9:1:899999999992 --3:-4:-5:7 -3:-4:-5:-17 --3:4:-5:-17 -3:4:-5:7 --3:4:5:-7 -3:-4:5:-7 -9999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890 -3.2:5.7:8.9:27.14 --3.2:5.197:6.05:-10.5804 -&bmodpow -3:4:8:1 -3:4:7:4 -3:4:7:4 -77777:777:123456789:99995084 -3.2:6.2:5.2:2.970579856718063040273642739529400818 -&fmul -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:NaNmul:NaN -+inf:NaNmul:NaN -NaNmul:+inf:NaN -NaNmul:-inf:NaN -+inf:+inf:inf -+inf:-inf:-inf -+inf:-inf:-inf -+inf:+inf:inf -+inf:123.34:inf -+inf:-123.34:-inf --inf:123.34:-inf --inf:-123.34:inf -123.34:+inf:inf --123.34:+inf:-inf -123.34:-inf:-inf --123.34:-inf:inf -+0:+0:0 -+0:+1:0 -+1:+0:0 -+0:-1:0 --1:+0:0 -+123456789123456789:+0:0 -+0:+123456789123456789:0 --1:-1:1 --1:+1:-1 -+1:-1:-1 -+1:+1:1 -+2:+3:6 --2:+3:-6 -+2:-3:-6 --2:-3:6 -+111:+111:12321 -+10101:+10101:102030201 -+1001001:+1001001:1002003002001 -+100010001:+100010001:10002000300020001 -+10000100001:+10000100001:100002000030000200001 -+11111111111:+9:99999999999 -+22222222222:+9:199999999998 -+33333333333:+9:299999999997 -+44444444444:+9:399999999996 -+55555555555:+9:499999999995 -+66666666666:+9:599999999994 -+77777777777:+9:699999999993 -+88888888888:+9:799999999992 -+99999999999:+9:899999999991 -6:120:720 -10:10000:100000 -&fdiv-list -0:0:NaN,NaN -0:1:0,0 -9:4:2.25,1 -9:5:1.8,4 -# bug in v1.74 with bdiv in list context, when $y is 1 or -1 -2.1:-1:-2.1,0 -2.1:1:2.1,0 --2.1:-1:2.1,0 --2.1:1:-2.1,0 -&fdiv -$div_scale = 40; $round_mode = 'even' -abc:abc:NaN -abc:+1:abc:NaN -+1:abc:NaN --1:abc:NaN -0:abc:NaN -+0:+0:NaN -+0:+1:0 -+1:+0:inf -+3214:+0:inf -+0:-1:0 --1:+0:-inf --3214:+0:-inf -+1:+1:1 --1:-1:1 -+1:-1:-1 --1:+1:-1 -+1:+2:0.5 -+2:+1:2 -123:+inf:0 -123:-inf:0 -+10:+5:2 -+100:+4:25 -+1000:+8:125 -+10000:+16:625 -+10000:-16:-625 -+999999999999:+9:111111111111 -+999999999999:+99:10101010101 -+999999999999:+999:1001001001 -+999999999999:+9999:100010001 -+999999999999999:+99999:10000100001 -+1000000000:+9:111111111.1111111111111111111111111111111 -+2000000000:+9:222222222.2222222222222222222222222222222 -+3000000000:+9:333333333.3333333333333333333333333333333 -+4000000000:+9:444444444.4444444444444444444444444444444 -+5000000000:+9:555555555.5555555555555555555555555555556 -+6000000000:+9:666666666.6666666666666666666666666666667 -+7000000000:+9:777777777.7777777777777777777777777777778 -+8000000000:+9:888888888.8888888888888888888888888888889 -+9000000000:+9:1000000000 -+35500000:+113:314159.2920353982300884955752212389380531 -+71000000:+226:314159.2920353982300884955752212389380531 -+106500000:+339:314159.2920353982300884955752212389380531 -+1000000000:+3:333333333.3333333333333333333333333333333 -2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447 -123456:1:123456 -$div_scale = 20 -+1000000000:+9:111111111.11111111111 -+2000000000:+9:222222222.22222222222 -+3000000000:+9:333333333.33333333333 -+4000000000:+9:444444444.44444444444 -+5000000000:+9:555555555.55555555556 -+6000000000:+9:666666666.66666666667 -+7000000000:+9:777777777.77777777778 -+8000000000:+9:888888888.88888888889 -+9000000000:+9:1000000000 -1:10:0.1 -1:100:0.01 -1:1000:0.001 -1:10000:0.0001 -1:504:0.001984126984126984127 -2:1.987654321:1.0062111801179738436 -123456789.123456789123456789123456789:1:123456789.12345678912 -# the next two cases are the "old" behaviour, but are now (>v0.01) different -#+35500000:+113:314159.292035398230088 -#+71000000:+226:314159.292035398230088 -+35500000:+113:314159.29203539823009 -+71000000:+226:314159.29203539823009 -+106500000:+339:314159.29203539823009 -+1000000000:+3:333333333.33333333333 -$div_scale = 1 -# round to accuracy 1 after bdiv -+124:+3:40 -123456789.1234:1:100000000 -# reset scale for further tests -$div_scale = 40 -&fmod -+9:4:1 -+9:5:4 -+9000:56:40 -+56:9000:56 -# inf handling, see table in doc -0:inf:0 -0:-inf:0 -5:inf:5 -5:-inf:5 --5:inf:-5 --5:-inf:-5 -inf:5:0 --inf:5:0 -inf:-5:0 --inf:-5:0 -5:5:0 --5:-5:0 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:8 -inf:0:inf -# exceptions to reminder rule --inf:0:-inf --8:0:-8 -0:0:NaN -abc:abc:NaN -abc:1:abc:NaN -1:abc:NaN -0:0:NaN -0:1:0 -1:0:1 -0:-1:0 --1:0:-1 -1:1:0 --1:-1:0 -1:-1:0 --1:1:0 -1:2:1 -2:1:0 -1000000000:9:1 -2000000000:9:2 -3000000000:9:3 -4000000000:9:4 -5000000000:9:5 -6000000000:9:6 -7000000000:9:7 -8000000000:9:8 -9000000000:9:0 -35500000:113:33 -71000000:226:66 -106500000:339:99 -1000000000:3:1 -10:5:0 -100:4:0 -1000:8:0 -10000:16:0 -999999999999:9:0 -999999999999:99:0 -999999999999:999:0 -999999999999:9999:0 -999999999999999:99999:0 --9:+5:1 -+9:-5:-1 --9:-5:-4 --5:3:1 --2:3:1 -4:3:1 -1:3:1 --5:-3:-2 --2:-3:-2 -4:-3:-2 -1:-3:-2 -4095:4095:0 -100041000510123:3:0 -152403346:12345:4321 -87654321:87654321:0 -# now some floating point tests -123:2.5:0.5 -1230:2.5:0 -123.4:2.5:0.9 -123e1:25:5 --2.1:1:0.9 -2.1:1:0.1 --2.1:-1:-0.1 -2.1:-1:-0.9 --3:1:0 -3:1:0 --3:-1:0 -3:-1:0 -&ffac -Nanfac:NaN --1:NaN -+inf:inf --inf:NaN -0:1 -1:1 -2:2 -3:6 -4:24 -5:120 -6:720 -10:3628800 -11:39916800 -12:479001600 -&froot -# sqrt() -+0:2:0 -+1:2:1 --1:2:NaN -# -$x ** (1/2) => -$y, but not in froot() --123.456:2:NaN -+inf:2:inf --inf:2:NaN -2:2:1.41421356237309504880168872420969807857 --2:2:NaN -4:2:2 -9:2:3 -16:2:4 -100:2:10 -123.456:2:11.11107555549866648462149404118219234119 -15241.38393:2:123.4559999756998444766131352122991626468 -1.44:2:1.2 -12:2:3.464101615137754587054892683011744733886 -0.49:2:0.7 -0.0049:2:0.07 -# invalid ones -1:NaN:NaN --1:NaN:NaN -0:NaN:NaN --inf:NaN:NaN -+inf:NaN:NaN -NaN:0:NaN -NaN:2:NaN -NaN:inf:NaN -NaN:inf:NaN -12:-inf:NaN -12:inf:NaN -+0:0:NaN -+1:0:NaN --1:0:NaN --2:0:NaN --123.45:0:NaN -+inf:0:NaN -12:1:12 --12:1:NaN -8:-1:NaN --8:-1:NaN -# cubic root -8:3:2 --8:3:NaN -# fourths root -16:4:2 -81:4:3 -# see t/bigroot() for more tests -&fsqrt -+0:0 --1:NaN --2:NaN --16:NaN --123.45:NaN -nanfsqrt:NaN -+inf:inf --inf:NaN -1:1 -2:1.41421356237309504880168872420969807857 -4:2 -9:3 -16:4 -100:10 -123.456:11.11107555549866648462149404118219234119 -15241.38393:123.4559999756998444766131352122991626468 -1.44:1.2 -# sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4 -1.44E10:120000 -2e10:141421.356237309504880168872420969807857 -144e20:120000000000 -# proved to be an endless loop under 7-9 -12:3.464101615137754587054892683011744733886 -0.49:0.7 -0.0049:0.07 -&is_nan -123:0 -abc:1 -NaN:1 --123:0 -&is_inf -+inf::1 --inf::1 -abc::0 -1::0 -NaN::0 --1::0 -+inf:-:0 -+inf:+:1 --inf:-:1 --inf:+:0 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 -&is_odd -abc:0 -0:0 --1:1 --3:1 -1:1 -3:1 -1000001:1 -1000002:0 -+inf:0 --inf:0 -123.45:0 --123.45:0 -2:0 -&is_int -NaNis_int:0 -0:1 -1:1 -2:1 --2:1 --1:1 --inf:0 -+inf:0 -123.4567:0 --0.1:0 --0.002:0 -&is_even -abc:0 -0:1 --1:0 --3:0 -1:0 -3:0 -1000001:0 -1000002:1 -2:1 -+inf:0 --inf:0 -123.456:0 --123.456:0 -0.01:0 --0.01:0 -120:1 -1200:1 --1200:1 -&is_positive -0:0 -1:1 --1:0 --123:0 -NaN:0 --inf:0 -+inf:1 -&is_negative -0:0 -1:0 --1:1 --123:1 -NaN:0 --inf:1 -+inf:0 -&parts -0:0 1 -1:1 0 -123:123 0 --123:-123 0 --1200:-12 2 -NaNparts:NaN NaN -+inf:inf inf --inf:-inf inf -&exponent -0:1 -1:0 -123:0 --123:0 --1200:2 -+inf:inf --inf:inf -NaNexponent:NaN -&mantissa -0:0 -1:1 -123:123 --123:-123 --1200:-12 -+inf:inf --inf:-inf -NaNmantissa:NaN -&length -123:3 --123:3 -0:1 -1:1 -12345678901234567890:20 -&is_zero -NaNzero:0 -+inf:0 --inf:0 -0:1 --1:0 -1:0 -&is_one -NaNone:0 -+inf:0 --inf:0 -0:0 -2:0 -1:1 --1:0 --2:0 -&ffloor -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-52 -12.2:12 -0.12345:0 -0.123456:0 -0.1234567:0 -0.12345678:0 -0.123456789:0 -&fceil -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-51 -12.2:13 diff --git a/lib/Math/BigInt/t/bigfltpm.t b/lib/Math/BigInt/t/bigfltpm.t deleted file mode 100644 index a41996e8ed..0000000000 --- a/lib/Math/BigInt/t/bigfltpm.t +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bigfltpm.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../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 => 2308 - + 5; # own tests - } - -use Math::BigInt lib => 'Calc'; -use Math::BigFloat; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigFloat"; -$CL = "Math::BigInt::Calc"; - -ok ($class->config()->{class},$class); -ok ($class->config()->{with}, $CL); - -# bug #17447: Can't call method Math::BigFloat->bsub, not a valid method -my $c = Math::BigFloat->new( '123.3' ); -ok ($c->fsub(123) eq '0.3', 1); # calling fsub on a BigFloat works - -# Bug until BigInt v1.86, the scale wasn't treated as a scalar: -$c = Math::BigFloat->new('0.008'); my $d = Math::BigFloat->new(3); -my $e = $c->bdiv(Math::BigFloat->new(3),$d); - -ok ($e,'0.00267'); # '0.008 / 3 => 0.0027'); -ok (ref($e->{_e}->[0]), ''); # 'Not a BigInt'); - -require 'bigfltpm.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/bigintc.t b/lib/Math/BigInt/t/bigintc.t deleted file mode 100644 index 5dbace06a3..0000000000 --- a/lib/Math/BigInt/t/bigintc.t +++ /dev/null @@ -1,464 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use Test; - -BEGIN - { - $| = 1; - chdir 't' if -d 't'; - unshift @INC, '../lib'; # for running manually - if ($^O eq 'unicos') # the tests hang under "unicos" - { - print "1..0\n"; - exit(0); - } - plan tests => 375; - } - -use Math::BigInt::Calc; - -my ($BASE_LEN, $AND_BITS, $XOR_BITS, $OR_BITS, $BASE_LEN_SMALL, $MAX_VAL) = - Math::BigInt::Calc->_base_len(); - -print "# BASE_LEN = $BASE_LEN\n"; -print "# MAX_VAL = $MAX_VAL\n"; -print "# AND_BITS = $AND_BITS\n"; -print "# XOR_BITS = $XOR_BITS\n"; -print "# IOR_BITS = $OR_BITS\n"; - -# testing of Math::BigInt::Calc - -my $C = 'Math::BigInt::Calc'; # pass classname to sub's - -# _new and _str -my $x = $C->_new("123"); my $y = $C->_new("321"); -ok (ref($x),'ARRAY'); ok ($C->_str($x),123); ok ($C->_str($y),321); - -############################################################################### -# _add, _sub, _mul, _div -ok ($C->_str($C->_add($x,$y)),444); -ok ($C->_str($C->_sub($x,$y)),123); -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($C->_div($x,$y)),123); - -############################################################################### -# check that mul/div doesn't change $y -# and returns the same reference, not something new -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($x),39483); ok ($C->_str($y),321); - -ok ($C->_str($C->_div($x,$y)),123); -ok ($C->_str($x),123); ok ($C->_str($y),321); - -$x = $C->_new("39483"); -my ($x1,$r1) = $C->_div($x,$y); -ok ("$x1","$x"); -$C->_inc($x1); -ok ("$x1","$x"); -ok ($C->_str($r1),'0'); - -$x = $C->_new("39483"); # reset - -############################################################################### -my $z = $C->_new("2"); -ok ($C->_str($C->_add($x,$z)),39485); -my ($re,$rr) = $C->_div($x,$y); - -ok ($C->_str($re),123); ok ($C->_str($rr),2); - -# is_zero, _is_one, _one, _zero -ok ($C->_is_zero($x)||0,0); -ok ($C->_is_one($x)||0,0); - -ok ($C->_str($C->_zero()),"0"); -ok ($C->_str($C->_one()),"1"); - -# _two() and _ten() -ok ($C->_str($C->_two()),"2"); -ok ($C->_str($C->_ten()),"10"); -ok ($C->_is_ten($C->_two()),0); -ok ($C->_is_two($C->_two()),1); -ok ($C->_is_ten($C->_ten()),1); -ok ($C->_is_two($C->_ten()),0); - -ok ($C->_is_one($C->_one()),1); -ok ($C->_is_one($C->_two()),0); -ok ($C->_is_one($C->_ten()),0); - -ok ($C->_is_one($C->_zero()) || 0,0); - -ok ($C->_is_zero($C->_zero()),1); - -ok ($C->_is_zero($C->_one()) || 0,0); - -# is_odd, is_even -ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero())||0,0); -ok ($C->_is_even($C->_one()) || 0,0); ok ($C->_is_even($C->_zero()),1); - -# _len -for my $method (qw/_alen _len/) - { - $x = $C->_new("1"); ok ($C->$method($x),1); - $x = $C->_new("12"); ok ($C->$method($x),2); - $x = $C->_new("123"); ok ($C->$method($x),3); - $x = $C->_new("1234"); ok ($C->$method($x),4); - $x = $C->_new("12345"); ok ($C->$method($x),5); - $x = $C->_new("123456"); ok ($C->$method($x),6); - $x = $C->_new("1234567"); ok ($C->$method($x),7); - $x = $C->_new("12345678"); ok ($C->$method($x),8); - $x = $C->_new("123456789"); ok ($C->$method($x),9); - - $x = $C->_new("8"); ok ($C->$method($x),1); - $x = $C->_new("21"); ok ($C->$method($x),2); - $x = $C->_new("321"); ok ($C->$method($x),3); - $x = $C->_new("4321"); ok ($C->$method($x),4); - $x = $C->_new("54321"); ok ($C->$method($x),5); - $x = $C->_new("654321"); ok ($C->$method($x),6); - $x = $C->_new("7654321"); ok ($C->$method($x),7); - $x = $C->_new("87654321"); ok ($C->$method($x),8); - $x = $C->_new("987654321"); ok ($C->$method($x),9); - - $x = $C->_new("0"); ok ($C->$method($x),1); - $x = $C->_new("20"); ok ($C->$method($x),2); - $x = $C->_new("320"); ok ($C->$method($x),3); - $x = $C->_new("4320"); ok ($C->$method($x),4); - $x = $C->_new("54320"); ok ($C->$method($x),5); - $x = $C->_new("654320"); ok ($C->$method($x),6); - $x = $C->_new("7654320"); ok ($C->$method($x),7); - $x = $C->_new("87654320"); ok ($C->$method($x),8); - $x = $C->_new("987654320"); ok ($C->$method($x),9); - - for (my $i = 1; $i < 9; $i++) - { - my $a = "$i" . '0' x ($i-1); - $x = $C->_new($a); - print "# Tried len '$a'\n" unless ok ($C->_len($x),$i); - } - } - -# _digit -$x = $C->_new("123456789"); -ok ($C->_digit($x,0),9); -ok ($C->_digit($x,1),8); -ok ($C->_digit($x,2),7); -ok ($C->_digit($x,-1),1); -ok ($C->_digit($x,-2),2); -ok ($C->_digit($x,-3),3); - -# _copy -foreach (qw/ 1 12 123 1234 12345 123456 1234567 12345678 123456789/) - { - $x = $C->_new("$_"); - ok ($C->_str($C->_copy($x)),"$_"); - ok ($C->_str($x),"$_"); # did _copy destroy original x? - } - -# _zeros -$x = $C->_new("1256000000"); ok ($C->_zeros($x),6); -$x = $C->_new("152"); ok ($C->_zeros($x),0); -$x = $C->_new("123000"); ok ($C->_zeros($x),3); -$x = $C->_new("0"); ok ($C->_zeros($x),0); - -# _lsft, _rsft -$x = $C->_new("10"); $y = $C->_new("3"); -ok ($C->_str($C->_lsft($x,$y,10)),10000); -$x = $C->_new("20"); $y = $C->_new("3"); -ok ($C->_str($C->_lsft($x,$y,10)),20000); - -$x = $C->_new("128"); $y = $C->_new("4"); -ok ($C->_str($C->_lsft($x,$y,2)), 128 << 4); - -$x = $C->_new("1000"); $y = $C->_new("3"); -ok ($C->_str($C->_rsft($x,$y,10)),1); -$x = $C->_new("20000"); $y = $C->_new("3"); -ok ($C->_str($C->_rsft($x,$y,10)),20); -$x = $C->_new("256"); $y = $C->_new("4"); -ok ($C->_str($C->_rsft($x,$y,2)),256 >> 4); - -$x = $C->_new("6411906467305339182857313397200584952398"); -$y = $C->_new("45"); -ok ($C->_str($C->_rsft($x,$y,10)),0); - -# _acmp -$x = $C->_new("123456789"); -$y = $C->_new("987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); -$x = $C->_new("12"); -$y = $C->_new("12"); -ok ($C->_acmp($x,$y),0); -$x = $C->_new("21"); -ok ($C->_acmp($x,$y),1); -ok ($C->_acmp($y,$x),-1); -$x = $C->_new("123456789"); -$y = $C->_new("1987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),+1); - -$x = $C->_new("1234567890123456789"); -$y = $C->_new("987654321012345678"); -ok ($C->_acmp($x,$y),1); -ok ($C->_acmp($y,$x),-1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); - -$x = $C->_new("1234"); -$y = $C->_new("987654321012345678"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); - -# _modinv -$x = $C->_new("8"); -$y = $C->_new("5033"); -my ($xmod,$sign) = $C->_modinv($x,$y); -ok ($C->_str($xmod),'629'); # -629 % 5033 == 4404 -ok ($sign, '-'); - -# _div -$x = $C->_new("3333"); $y = $C->_new("1111"); -ok ($C->_str(scalar $C->_div($x,$y)),3); -$x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); -ok ($C->_str($x),30); ok ($C->_str($y),3); -$x = $C->_new("123"); $y = $C->_new("1111"); -($x,$y) = $C->_div($x,$y); ok ($C->_str($x),0); ok ($C->_str($y),123); - -# _num -foreach (qw/1 12 123 1234 12345 1234567 12345678 123456789 1234567890/) - { - $x = $C->_new("$_"); - ok (ref($x)||'','ARRAY'); ok ($C->_str($x),"$_"); - $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,$_); - } - -# _sqrt -$x = $C->_new("144"); ok ($C->_str($C->_sqrt($x)),'12'); -$x = $C->_new("144000000000000"); ok ($C->_str($C->_sqrt($x)),'12000000'); - -# _root -$x = $C->_new("81"); my $n = $C->_new("3"); # 4*4*4 = 64, 5*5*5 = 125 -ok ($C->_str($C->_root($x,$n)),'4'); # 4.xx => 4.0 -$x = $C->_new("81"); $n = $C->_new("4"); # 3*3*3*3 == 81 -ok ($C->_str($C->_root($x,$n)),'3'); - -# _pow (and _root) -$x = $C->_new("0"); $n = $C->_new("3"); # 0 ** y => 0 -ok ($C->_str($C->_pow($x,$n)), 0); -$x = $C->_new("3"); $n = $C->_new("0"); # x ** 0 => 1 -ok ($C->_str($C->_pow($x,$n)), 1); -$x = $C->_new("1"); $n = $C->_new("3"); # 1 ** y => 1 -ok ($C->_str($C->_pow($x,$n)), 1); -$x = $C->_new("5"); $n = $C->_new("1"); # x ** 1 => x -ok ($C->_str($C->_pow($x,$n)), 5); - -$x = $C->_new("81"); $n = $C->_new("3"); # 81 ** 3 == 531441 -ok ($C->_str($C->_pow($x,$n)),81 ** 3); - -ok ($C->_str($C->_root($x,$n)),81); - -$x = $C->_new("81"); -ok ($C->_str($C->_pow($x,$n)),81 ** 3); -ok ($C->_str($C->_pow($x,$n)),'150094635296999121'); # 531441 ** 3 == - -ok ($C->_str($C->_root($x,$n)),'531441'); -ok ($C->_str($C->_root($x,$n)),'81'); - -$x = $C->_new("81"); $n = $C->_new("14"); -ok ($C->_str($C->_pow($x,$n)),'523347633027360537213511521'); -ok ($C->_str($C->_root($x,$n)),'81'); - -$x = $C->_new("523347633027360537213511520"); -ok ($C->_str($C->_root($x,$n)),'80'); - -$x = $C->_new("523347633027360537213511522"); -ok ($C->_str($C->_root($x,$n)),'81'); - -my $res = [ qw/9 31 99 316 999 3162 9999 31622 99999/ ]; - -# 99 ** 2 = 9801, 999 ** 2 = 998001 etc -for my $i (2 .. 9) - { - $x = '9' x $i; $x = $C->_new($x); - $n = $C->_new("2"); - my $rc = '9' x ($i-1). '8' . '0' x ($i-1) . '1'; - print "# _pow( ", '9' x $i, ", 2) \n" unless - ok ($C->_str($C->_pow($x,$n)),$rc); - - # if $i > $BASE_LEN, the test takes a really long time: - if ($i <= $BASE_LEN) - { - $x = '9' x $i; $x = $C->_new($x); - $n = '9' x $i; $n = $C->_new($n); - print "# _root( ", '9' x $i, ", ", 9 x $i, ") \n"; - print "# _root( ", '9' x $i, ", ", 9 x $i, ") \n" unless - ok ($C->_str($C->_root($x,$n)),'1'); - - $x = '9' x $i; $x = $C->_new($x); - $n = $C->_new("2"); - print "# BASE_LEN $BASE_LEN _root( ", '9' x $i, ", ", 9 x $i, ") \n" unless - ok ($C->_str($C->_root($x,$n)), $res->[$i-2]); - } - else - { - ok ("skipped $i", "skipped $i"); - ok ("skipped $i", "skipped $i"); - } - } - -############################################################################## -# _fac -$x = $C->_new("0"); ok ($C->_str($C->_fac($x)),'1'); -$x = $C->_new("1"); ok ($C->_str($C->_fac($x)),'1'); -$x = $C->_new("2"); ok ($C->_str($C->_fac($x)),'2'); -$x = $C->_new("3"); ok ($C->_str($C->_fac($x)),'6'); -$x = $C->_new("4"); ok ($C->_str($C->_fac($x)),'24'); -$x = $C->_new("5"); ok ($C->_str($C->_fac($x)),'120'); -$x = $C->_new("10"); ok ($C->_str($C->_fac($x)),'3628800'); -$x = $C->_new("11"); ok ($C->_str($C->_fac($x)),'39916800'); -$x = $C->_new("12"); ok ($C->_str($C->_fac($x)),'479001600'); -$x = $C->_new("13"); ok ($C->_str($C->_fac($x)),'6227020800'); - -# test that _fac modifes $x in place for small arguments -$x = $C->_new("3"); $C->_fac($x); ok ($C->_str($x),'6'); -$x = $C->_new("13"); $C->_fac($x); ok ($C->_str($x),'6227020800'); - -############################################################################## -# _inc and _dec -foreach (qw/1 11 121 1231 12341 1234561 12345671 123456781 1234567891/) - { - $x = $C->_new("$_"); $C->_inc($x); - print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x),substr($_,0,length($_)-1) . '2'); - $C->_dec($x); ok ($C->_str($x),$_); - } -foreach (qw/19 119 1219 12319 1234519 12345619 123456719 1234567819/) - { - $x = $C->_new("$_"); $C->_inc($x); - print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x),substr($_,0,length($_)-2) . '20'); - $C->_dec($x); ok ($C->_str($x),$_); - } -foreach (qw/999 9999 99999 9999999 99999999 999999999 9999999999 99999999999/) - { - $x = $C->_new("$_"); $C->_inc($x); - print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x), '1' . '0' x (length($_))); - $C->_dec($x); ok ($C->_str($x),$_); - } - -$x = $C->_new("1000"); $C->_inc($x); ok ($C->_str($x),'1001'); -$C->_dec($x); ok ($C->_str($x),'1000'); - -my $BL; -{ - no strict 'refs'; - $BL = &{"$C"."::_base_len"}(); -} - -$x = '1' . '0' x $BL; -$z = '1' . '0' x ($BL-1); $z .= '1'; -$x = $C->_new($x); $C->_inc($x); ok ($C->_str($x),$z); - -$x = '1' . '0' x $BL; $z = '9' x $BL; -$x = $C->_new($x); $C->_dec($x); ok ($C->_str($x),$z); - -# should not happen: -# $x = $C->_new("-2"); $y = $C->_new("4"); ok ($C->_acmp($x,$y),-1); - -############################################################################### -# _mod -$x = $C->_new("1000"); $y = $C->_new("3"); -ok ($C->_str(scalar $C->_mod($x,$y)),1); -$x = $C->_new("1000"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_mod($x,$y)),0); - -# _and, _or, _xor -$x = $C->_new("5"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_xor($x,$y)),7); -$x = $C->_new("5"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_or($x,$y)),7); -$x = $C->_new("5"); $y = $C->_new("3"); -ok ($C->_str(scalar $C->_and($x,$y)),1); - -# _from_hex, _from_bin, _from_oct -ok ($C->_str( $C->_from_hex("0xFf")),255); -ok ($C->_str( $C->_from_bin("0b10101011")),160+11); -ok ($C->_str( $C->_from_oct("0100")), 8*8); -ok ($C->_str( $C->_from_oct("01000")), 8*8*8); -ok ($C->_str( $C->_from_oct("010001")), 8*8*8*8+1); -ok ($C->_str( $C->_from_oct("010007")), 8*8*8*8+7); - -# _as_hex, _as_bin, as_oct -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("128")))), 128); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("128")))), 128); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("128")))), 128); - -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456")))), 123456); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456789")))), "123456789"); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("1234567890123")))), "1234567890123"); - -my $long = '123456789012345678901234567890'; -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("0")))), 0); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("0")))), 0); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("0")))), 0); -ok ($C->_as_hex( $C->_new("0")), '0x0'); -ok ($C->_as_bin( $C->_new("0")), '0b0'); -ok ($C->_as_oct( $C->_new("0")), '00'); -ok ($C->_as_hex( $C->_new("12")), '0xc'); -ok ($C->_as_bin( $C->_new("12")), '0b1100'); -ok ($C->_as_oct( $C->_new("64")), '0100'); - -# _1ex -ok ($C->_str($C->_1ex(0)), "1"); -ok ($C->_str($C->_1ex(1)), "10"); -ok ($C->_str($C->_1ex(2)), "100"); -ok ($C->_str($C->_1ex(12)), "1000000000000"); -ok ($C->_str($C->_1ex(16)), "10000000000000000"); - -# _check -$x = $C->_new("123456789"); -ok ($C->_check($x),0); -ok ($C->_check(123),'123 is not a reference'); - -############################################################################### -# __strip_zeros - -{ - no strict 'refs'; - # correct empty arrays - $x = &{$C."::__strip_zeros"}([]); ok (@$x,1); ok ($x->[0],0); - # don't strip single elements - $x = &{$C."::__strip_zeros"}([0]); ok (@$x,1); ok ($x->[0],0); - $x = &{$C."::__strip_zeros"}([1]); ok (@$x,1); ok ($x->[0],1); - # don't strip non-zero elements - $x = &{$C."::__strip_zeros"}([0,1]); - ok (@$x,2); ok ($x->[0],0); ok ($x->[1],1); - $x = &{$C."::__strip_zeros"}([0,1,2]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); - - # but strip leading zeros - $x = &{$C."::__strip_zeros"}([0,1,2,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); - - $x = &{$C."::__strip_zeros"}([0,1,2,0,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); - - $x = &{$C."::__strip_zeros"}([0,1,2,0,0,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); - - # collapse multiple zeros - $x = &{$C."::__strip_zeros"}([0,0,0,0]); - ok (@$x,1); ok ($x->[0],0); -} - -# done - -1; - diff --git a/lib/Math/BigInt/t/bigintpm.inc b/lib/Math/BigInt/t/bigintpm.inc deleted file mode 100644 index 87140ba44d..0000000000 --- a/lib/Math/BigInt/t/bigintpm.inc +++ /dev/null @@ -1,2511 +0,0 @@ -#include this file into another for subclass testing - -my $version = ${"$class\::VERSION"}; - -use strict; - -############################################################################## -# for testing inheritance of _swap - -package Math::Foo; - -use Math::BigInt lib => $main::CL; -use vars qw/@ISA/; -@ISA = (qw/Math::BigInt/); - -use overload -# customized overload for sub, since original does not use swap there -'-' => sub { my @a = ref($_[0])->_swap(@_); - $a[0]->bsub($a[1])}; - -sub _swap - { - # a fake _swap, which reverses the params - my $self = shift; # for override in subclass - if ($_[2]) - { - my $c = ref ($_[0] ) || 'Math::Foo'; - return ( $_[0]->copy(), $_[1] ); - } - else - { - return ( Math::Foo->new($_[1]), $_[0] ); - } - } - -############################################################################## -package main; - -my $CALC = $class->config()->{lib}; ok ($CALC,$CL); - -my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class); - -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - next if /^#/; # skip comments - if (s/^&//) - { - $f = $_; next; - } - elsif (/^\$/) - { - $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next; - } - - @args = split(/:/,$_,99); $ans = pop(@args); - $expected_class = $class; - if ($ans =~ /(.*?)=(.*)/) - { - $expected_class = $2; $ans = $1; - } - $try = "\$x = $class->new(\"$args[0]\");"; - if ($f eq "bnorm") - { - $try = "\$x = $class->bnorm(\"$args[0]\");"; - # some is_xxx tests - } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) { - $try .= "\$x->$f() || 0;"; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "binf") { - $try .= "\$x->binf('$args[1]');"; - } elsif ($f eq "bone") { - $try .= "\$x->bone('$args[1]');"; - # some unary ops - } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) { - $try .= "\$x->$f();"; - } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "exponent"){ - # ->bstr() to see if an object is returned - $try .= '$x = $x->exponent()->bstr();'; - } elsif ($f eq "mantissa"){ - # ->bstr() to see if an object is returned - $try .= '$x = $x->mantissa()->bstr();'; - } elsif ($f eq "parts"){ - $try .= '($m,$e) = $x->parts();'; - # ->bstr() to see if an object is returned - $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;'; - $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;'; - $try .= '"$m,$e";'; - }elsif ($f eq "bexp"){ - $try .= "\$x->bexp();"; - } elsif ($f eq "bpi"){ - $try .= "$class\->bpi(\$x);"; - } else { - # binary ops - $try .= "\$y = $class->new('$args[1]');"; - if ($f eq "bcmp") - { - $try .= '$x->bcmp($y);'; - } elsif ($f eq "bround") { - $try .= "$round_mode; \$x->bround(\$y);"; - } elsif ($f eq "bacmp"){ - $try .= '$x->bacmp($y);'; - } elsif ($f eq "badd"){ - $try .= '$x + $y;'; - } elsif ($f eq "bsub"){ - $try .= '$x - $y;'; - } elsif ($f eq "bmul"){ - $try .= '$x * $y;'; - } elsif ($f eq "bdiv"){ - $try .= '$x / $y;'; - } elsif ($f eq "bdiv-list"){ - $try .= 'join (",",$x->bdiv($y));'; - # overload via x= - } elsif ($f =~ /^.=$/){ - $try .= "\$x $f \$y;"; - # overload via x - } elsif ($f =~ /^.$/){ - $try .= "\$x $f \$y;"; - } elsif ($f eq "bmod"){ - $try .= '$x % $y;'; - } elsif ($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 "blsft"){ - if (defined $args[2]) - { - $try .= "\$x->blsft(\$y,$args[2]);"; - } - else - { - $try .= "\$x << \$y;"; - } - }elsif ($f eq "brsft"){ - if (defined $args[2]) - { - $try .= "\$x->brsft(\$y,$args[2]);"; - } - else - { - $try .= "\$x >> \$y;"; - } - }elsif ($f eq "bnok"){ - $try .= "\$x->bnok(\$y);"; - }elsif ($f eq "broot"){ - $try .= "\$x->broot(\$y);"; - }elsif ($f eq "blog"){ - $try .= "\$x->blog(\$y);"; - }elsif ($f eq "band"){ - $try .= "\$x & \$y;"; - }elsif ($f eq "bior"){ - $try .= "\$x | \$y;"; - }elsif ($f eq "bxor"){ - $try .= "\$x ^ \$y;"; - }elsif ($f eq "bpow"){ - $try .= "\$x ** \$y;"; - } elsif( $f eq "bmodinv") { - $try .= "\$x->bmodinv(\$y);"; - }elsif ($f eq "digit"){ - $try .= "\$x->digit(\$y);"; - }elsif ($f eq "batan2"){ - $try .= "\$x->batan2(\$y);"; - } else { - # Functions with three arguments - $try .= "\$z = $class->new(\"$args[2]\");"; - - if( $f eq "bmodpow") { - $try .= "\$x->bmodpow(\$y,\$z);"; - } elsif ($f eq "bmuladd"){ - $try .= "\$x->bmuladd(\$y,\$z);"; - } else { warn "Unknown op '$f'"; } - } - } # end else all other ops - - $ans1 = eval $try; - # convert hex/binary targets to decimal - if ($ans =~ /^(0x0x|0b0b)/) - { - $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr(); - } - if ($ans eq "") - { - ok_undef ($ans1); - } - else - { - # print "try: $try ans: $ans1 $ans\n"; - print "# Tried: '$try'\n" if !ok ($ans1, $ans); - ok (ref($ans),$expected_class) if $expected_class ne $class; - } - # check internal state of number objects - is_valid($ans1,$f) if ref $ans1; - } # endwhile data tests -close DATA; - -# test some more -@a = (); -for (my $i = 1; $i < 10; $i++) - { - push @a, $i; - } -ok "@a", "1 2 3 4 5 6 7 8 9"; - -# test whether self-multiplication works correctly (result is 2**64) -$try = "\$x = $class->new('4294967296');"; -$try .= '$a = $x->bmul($x);'; -$ans1 = eval $try; -print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64); -# test self-pow -$try = "\$x = $class->new(10);"; -$try .= '$a = $x->bpow($x);'; -$ans1 = eval $try; -print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10); - -############################################################################### -# test whether op destroys args or not (should better not) - -$x = $class->new(3); -$y = $class->new(4); -$z = $x & $y; -ok ($x,3); -ok ($y,4); -ok ($z,0); -$z = $x | $y; -ok ($x,3); -ok ($y,4); -ok ($z,7); -$x = $class->new(1); -$y = $class->new(2); -$z = $x | $y; -ok ($x,1); -ok ($y,2); -ok ($z,3); - -$x = $class->new(5); -$y = $class->new(4); -$z = $x ^ $y; -ok ($x,5); -ok ($y,4); -ok ($z,1); - -$x = $class->new(-5); $y = -$x; -ok ($x, -5); - -$x = $class->new(-5); $y = abs($x); -ok ($x, -5); - -$x = $class->new(8); -$y = $class->new(-1); -$z = $class->new(5033); -my $u = $x->copy()->bmodpow($y,$z); -ok ($u,4404); -ok ($y,-1); -ok ($z,5033); - -$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5); -$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5); - -$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3); -$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3); - -$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3); -$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3); - -$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3); -$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3); - -############################################################################### -# check whether overloading cmp works -$try = "\$x = $class->new(0);"; -$try .= "\$y = 10;"; -$try .= "'false' if \$x ne \$y;"; -$ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "false" ); - -# we cant test for working cmpt with other objects here, we would need a dummy -# object with stringify overload for this. see Math::String tests as example - -############################################################################### -# check reversed order of arguments - -$try = "\$x = $class->new(10); \$x = 2 ** \$x;"; -$try .= "'ok' if \$x == 1024;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class->new(10); \$x = 2 * \$x;"; -$try .= "'ok' if \$x == 20;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class->new(10); \$x = 2 + \$x;"; -$try .= "'ok' if \$x == 12;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(10); \$x = 2 - \$x;"; -$try .= "'ok' if \$x == -8;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(10); \$x = 20 / \$x;"; -$try .= "'ok' if \$x == 2;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(3); \$x = 20 % \$x;"; -$try .= "'ok' if \$x == 2;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(7); \$x = 20 & \$x;"; -$try .= "'ok' if \$x == 4;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;"; -$try .= "'ok' if \$x == 0x27;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;"; -$try .= "'ok' if \$x == 0x27;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -############################################################################### -# check badd(4,5) form - -$try = "\$x = $class\->badd(4,5);"; -$try .= "'ok' if \$x == 9;"; -$ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "ok" ); - -############################################################################### -# check undefs: NOT DONE YET - -############################################################################### -# bool - -$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') } -$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') } - -############################################################################### -# objectify() - -@args = Math::BigInt::objectify(2,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); - -@args = Math::BigInt::objectify(0,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); - -@args = Math::BigInt::objectify(2,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); - -@args = Math::BigInt::objectify(2,4,5,6,7); -ok (scalar @args,5); # $class, 4, 5, 6, 7 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); ok (ref($args[1]),$args[0]); -ok ($args[2],5); ok (ref($args[2]),$args[0]); -ok ($args[3],6); ok (ref($args[3]),''); -ok ($args[4],7); ok (ref($args[4]),''); - -@args = Math::BigInt::objectify(2,$class,4,5,6,7); -ok (scalar @args,5); # $class, 4, 5, 6, 7 -ok ($args[0],$class); -ok ($args[1],4); ok (ref($args[1]),$args[0]); -ok ($args[2],5); ok (ref($args[2]),$args[0]); -ok ($args[3],6); ok (ref($args[3]),''); -ok ($args[4],7); ok (ref($args[4]),''); - -############################################################################### -# test whether an opp calls objectify properly or not (or at least does what -# it should do given non-objects, w/ or w/o objectify()) - -ok ($class->new(123)->badd(123),246); -ok ($class->badd(123,321),444); -ok ($class->badd(123,$class->new(321)),444); - -ok ($class->new(123)->bsub(122),1); -ok ($class->bsub(321,123),198); -ok ($class->bsub(321,$class->new(123)),198); - -ok ($class->new(123)->bmul(123),15129); -ok ($class->bmul(123,123),15129); -ok ($class->bmul(123,$class->new(123)),15129); - -ok ($class->new(15129)->bdiv(123),123); -ok ($class->bdiv(15129,123),123); -ok ($class->bdiv(15129,$class->new(123)),123); - -ok ($class->new(15131)->bmod(123),2); -ok ($class->bmod(15131,123),2); -ok ($class->bmod(15131,$class->new(123)),2); - -ok ($class->new(2)->bpow(16),65536); -ok ($class->bpow(2,16),65536); -ok ($class->bpow(2,$class->new(16)),65536); - -ok ($class->new(2**15)->brsft(1),2**14); -ok ($class->brsft(2**15,1),2**14); -ok ($class->brsft(2**15,$class->new(1)),2**14); - -ok ($class->new(2**13)->blsft(1),2**14); -ok ($class->blsft(2**13,1),2**14); -ok ($class->blsft(2**13,$class->new(1)),2**14); - -############################################################################### -# test for floating-point input (other tests in bnorm() below) - -$z = 1050000000000000; # may be int on systems with 64bit? -$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15 -$z = 1e+129; # definitely a float (may fail on UTS) -# don't compare to $z, since some Perl versions stringify $z into something -# like '1.e+129' or something equally ugly -$x = $class->new($z); ok ($x->bsstr(),'1e+129'); - -############################################################################### -# test for whitespace inlcuding newlines to be handled correctly - -# ok ($Math::BigInt::strict,1); # the default - -foreach my $c ( - qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/) - { - my $m = $class->new($c); - ok ($class->new("$c"),$m); - ok ($class->new(" $c"),$m); - ok ($class->new("$c "),$m); - ok ($class->new(" $c "),$m); - ok ($class->new("\n$c"),$m); - ok ($class->new("$c\n"),$m); - ok ($class->new("\n$c\n"),$m); - ok ($class->new(" \n$c\n"),$m); - ok ($class->new(" \n$c \n"),$m); - ok ($class->new(" \n$c\n "),$m); - ok ($class->new(" \n$c\n1"),'NaN'); - ok ($class->new("1 \n$c\n1"),'NaN'); - } - -############################################################################### -# prime number tests, also test for **= and length() -# found on: http://www.utm.edu/research/primes/notes/by_year.html - -# ((2^148)-1)/17 -$x = $class->new(2); $x **= 148; $x++; $x = $x / 17; -ok ($x,"20988936657440586486151264256610222593863921"); -ok ($x->length(),length "20988936657440586486151264256610222593863921"); - -# MM7 = 2^127-1 -$x = $class->new(2); $x **= 127; $x--; -ok ($x,"170141183460469231731687303715884105727"); - -$x = $class->new('215960156869840440586892398248'); -($x,$y) = $x->length(); -ok ($x,30); ok ($y,0); - -$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--; - -# 593573509*2^332162+1 has exactly 1,000,000 digits -# takes about 24 mins on 300 Mhz, so cannot be done yet ;) -#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++; -#ok ($x->length(),1_000_000); - -############################################################################### -# inheritance and overriding of _swap - -$x = Math::Foo->new(5); -$x = $x - 8; # 8 - 5 instead of 5-8 -ok ($x,3); -ok (ref($x),'Math::Foo'); - -$x = Math::Foo->new(5); -$x = 8 - $x; # 5 - 8 instead of 8 - 5 -ok ($x,-3); -ok (ref($x),'Math::Foo'); - -############################################################################### -# Test whether +inf eq inf -# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl -# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things -# like 1e100000 crash on some platforms. So simple test for the string 'inf' -$x = $class->new('+inf'); ok ($x,'inf'); - -############################################################################### -############################################################################### -# the followin tests only make sense with Math::BigInt::Calc or BareCalc or -# FastCalc - -exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al. - -############################################################################### -# check proper length of internal arrays - -my $bl = $CL->_base_len(); -my $BASE = '9' x $bl; -my $MAX = $BASE; -$BASE++; - -$x = $class->new($MAX); is_valid($x); # f.i. 9999 -$x += 1; ok ($x,$BASE); is_valid($x); # 10000 -$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again - -############################################################################### -# check numify - -$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1); -$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1)); - -# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...) -$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0); -$x = $class->new(-$BASE); ok ($x->numify(),-$BASE); -$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); -ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); - -############################################################################### -# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1 - -$x = $class->new($BASE-2); $x++; $x++; $x++; $x++; -if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); } - -$x = $class->new($BASE+3); $x++; -if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); } - -# test for +0 instead of int(): -$x = $class->new($MAX); ok ($x->length(), length($MAX)); - -############################################################################### -# test bug that $class->digit($string) did not work - -ok ($class->digit(123,2),1); - -############################################################################### -# bug in sub where number with at least 6 trailing zeros after any op failed - -$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z; -ok ($z, 100000); -ok ($x, 23456); - -############################################################################### -# bug in shortcut in mul() - -# construct a number with a zero-hole of BASE_LEN_SMALL -{ - my @bl = $CL->_base_len(); my $bl = $bl[4]; - - $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl; - $y = '1' x (2*$bl); - $x = $class->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; - } - $y .= $bl x (3*$bl-1) . $d . '0' x $bl; - ok ($x,$y); - - - ############################################################################# - # see if mul shortcut for small numbers works - - $x = '9' x $bl; - $x = $class->new($x); - # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001 - ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1'); -} - -############################################################################### -# bug with rest "-0" in div, causing further div()s to fail - -$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); - -ok ($y,'0'); is_valid($y); # $y not '-0' - -############################################################################### -# bug in $x->bmod($y) - -# if $x < 0 and $y > 0 -$x = $class->new('-629'); ok ($x->bmod(5033),4404); - -############################################################################### -# bone/binf etc as plain calls (Lite failed them) - -ok ($class->bzero(),0); -ok ($class->bone(),1); -ok ($class->bone('+'),1); -ok ($class->bone('-'),-1); -ok ($class->bnan(),'NaN'); -ok ($class->binf(),'inf'); -ok ($class->binf('+'),'inf'); -ok ($class->binf('-'),'-inf'); -ok ($class->binf('-inf'),'-inf'); - -############################################################################### -# is_one('-') - -ok ($class->new(1)->is_one('-'),0); -ok ($class->new(-1)->is_one('-'),1); -ok ($class->new(1)->is_one(),1); -ok ($class->new(-1)->is_one(),0); - -############################################################################### -# [perl #30609] bug with $x -= $x not being 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; - -############################################################################### -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return if !defined $x; - ok ($x,'undef'); - } - -############################################################################### -# sub to check validity of a BigInt internally, to ensure that no op leaves a -# number object in an invalid state (f.i. "-0") - -sub is_valid - { - my ($x,$f) = @_; - - my $e = 0; # error? - - # allow the check to pass for all Lite, and all MBI and subclasses - # ok as reference? - $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/; - - if (ref($x) ne 'Math::BigInt::Lite') - { - # has ok sign? - $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" - if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; - - $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; - $e = $CALC->_check($x->{value}) if $e eq '0'; - } - - # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); - - ok (1,$e." after op '$f'"); - } - -__DATA__ -&.= -1234:-345:1234-345 -&+= -1:2:3 --1:-2:-3 -&-= -1:2:-1 --1:-2:1 -&*= -2:3:6 --1:5:-5 -&%= -100:3:1 -8:9:8 --629:5033:4404 -&/= -100:3:33 --8:2:-4 -&|= -2:1:3 -&&= -5:7:5 -&^= -5:7:2 -&blog -NaNlog:2:NaN -122:NaNlog:NaN -NaNlog1:NaNlog:NaN -122:inf:NaN -inf:122:NaN -122:-inf:NaN --inf:122:NaN --inf:-inf:NaN -inf:inf:NaN -0:4:NaN --21:4:NaN -21:-21:NaN -# normal results -1024:2:10 -81:3:4 -# 3.01.. truncate -82:3:4 -# 3.9... truncate -80:3:3 -15625:5:6 -15626:5:6 -15624:5:5 -1000:10:3 -10000:10:4 -100000:10:5 -1000000:10:6 -10000000:10:7 -100000000:10:8 -8916100448256:12:12 -8916100448257:12:12 -8916100448255:12:11 -2251799813685248:8:17 -72057594037927936:2:56 -144115188075855872:2:57 -288230376151711744:2:58 -576460752303423488:2:59 -4096:2:12 -1329227995784915872903807060280344576:2:120 -# $x == $base => result 1 -3:3:1 -# $x < $base => result 0 ($base ** 0 <= $x) -3:4:0 -# $x == 1 => result 0 -1:5:0 -&is_negative -0:0 --1:1 -1:0 -+inf:0 --inf:1 -NaNneg:0 -&is_positive -0:0 --1:0 -1:1 -+inf:1 --inf:0 -NaNneg:0 -&is_int --inf:0 -+inf:0 -NaNis_int:0 -1:1 -0:1 -123e12:1 -&is_odd -abc:0 -0:0 -1:1 -3:1 --1:1 --3:1 -10000001:1 -10000002:0 -2:0 -120:0 -121:1 -&is_even -abc:0 -0:1 -1:0 -3:0 --1:0 --3:0 -10000001:0 -10000002:1 -2:1 -120:1 -121:0 -&bacmp -+0:-0:0 -+0:+1:-1 --1:+1:0 -+1:-1:0 --1:+2:-1 -+2:-1:1 --123456789:+987654321:-1 -+123456789:-987654321:-1 -+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 -123:-inf:-1 --123:inf:-1 --123:-inf:-1 -123:inf:-1 -# return undef -+inf:NaN: -NaN:inf: --inf:NaN: -NaN:-inf: -&bnorm -0e999:0 -0e-999:0 --0e999:0 --0e-999:0 -123:123 -# binary input -0babc:NaN -0b123:NaN -0b0:0 --0b0:0 --0b1:-1 -0b0001:1 -0b001:1 -0b011:3 -0b101:5 -0b1001:9 -0b10001:17 -0b100001:33 -0b1000001:65 -0b10000001:129 -0b100000001:257 -0b1000000001:513 -0b10000000001:1025 -0b100000000001:2049 -0b1000000000001:4097 -0b10000000000001:8193 -0b100000000000001:16385 -0b1000000000000001:32769 -0b10000000000000001:65537 -0b100000000000000001:131073 -0b1000000000000000001:262145 -0b10000000000000000001:524289 -0b100000000000000000001:1048577 -0b1000000000000000000001:2097153 -0b10000000000000000000001:4194305 -0b100000000000000000000001:8388609 -0b1000000000000000000000001:16777217 -0b10000000000000000000000001:33554433 -0b100000000000000000000000001:67108865 -0b1000000000000000000000000001:134217729 -0b10000000000000000000000000001:268435457 -0b100000000000000000000000000001:536870913 -0b1000000000000000000000000000001:1073741825 -0b10000000000000000000000000000001:2147483649 -0b100000000000000000000000000000001:4294967297 -0b1000000000000000000000000000000001:8589934593 -0b10000000000000000000000000000000001:17179869185 -0b_101:NaN -0b1_0_1:5 -0b0_0_0_1:1 -# hex input --0x0:0 -0xabcdefgh:NaN -0x1234:4660 -0xabcdef:11259375 --0xABCDEF:-11259375 --0x1234:-4660 -0x12345678:305419896 -0x1_2_3_4_56_78:305419896 -0xa_b_c_d_e_f:11259375 -0x_123:NaN -0x9:9 -0x11:17 -0x21:33 -0x41:65 -0x81:129 -0x101:257 -0x201:513 -0x401:1025 -0x801:2049 -0x1001:4097 -0x2001:8193 -0x4001:16385 -0x8001:32769 -0x10001:65537 -0x20001:131073 -0x40001:262145 -0x80001:524289 -0x100001:1048577 -0x200001:2097153 -0x400001:4194305 -0x800001:8388609 -0x1000001:16777217 -0x2000001:33554433 -0x4000001:67108865 -0x8000001:134217729 -0x10000001:268435457 -0x20000001:536870913 -0x40000001:1073741825 -0x80000001:2147483649 -0x100000001:4294967297 -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 --inf:-inf -0inf:NaN -# abnormal input -:NaN -abc:NaN - 1 a:NaN -1bcd2:NaN -11111b:NaN -+1z:NaN --1z:NaN -# only one underscore between two digits -_123:NaN -_123_:NaN -123_:NaN -1__23:NaN -1E1__2:NaN -1_E12:NaN -1E_12:NaN -1_E_12:NaN -+_1E12:NaN -+0_1E2:100 -+0_0_1E2:100 --0_0_1E2:-100 --0_0_1E+0_0_2:-100 -E1:NaN -E23:NaN -1.23E1:NaN -1.23E-1:NaN -# bug with two E's in number being valid -1e2e3:NaN -1e2r:NaN -1e2.0:NaN -# bug with two '.' in number being valid -1.2.2:NaN -1.2.3e1:NaN --1.2.3:NaN --1.2.3e-4:NaN -1.2e3.4:NaN -1.2e-3.4:NaN -1.2.3.4:NaN -1.2.t:NaN -1..2:NaN -1..2e1:NaN -1..2e1..1:NaN -12e1..1:NaN -..2:NaN -.-2:NaN -# leading zeros -012:12 -0123:123 -01234:1234 -012345:12345 -0123456:123456 -01234567:1234567 -012345678:12345678 -0123456789:123456789 -01234567891:1234567891 -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 -+00:0 -+000:0 -000000000000000000:0 --0:0 --0000:0 -+1:1 -+01:1 -+001:1 -+00000100000:100000 -123456789:123456789 --1:-1 --01:-1 --001:-1 --123456789:-123456789 --00000100000:-100000 -1_2_3:123 -10000000000E-1_0:1 -1E2:100 -1E1:10 -1E0:1 -1.23E2:123 -100E-1:10 -# floating point input -# .2e2:20 -1.E3:1000 -1.01E2:101 -1010E-1:101 --1010E0:-1010 --1010E1:-10100 -1234.00:1234 -# non-integer numbers --1010E-2:NaN --1.01E+1:NaN --1.01E-1:NaN -&bnan -1:NaN -2:NaN -abc:NaN -&bone -2:+:1 -2:-:-1 -boneNaN:-:-1 -boneNaN:+:1 -2:abc:1 -3::1 -&binf -1:+:inf -2:-:-inf -3:abc:inf -&is_nan -123:0 -abc:1 -NaN:1 --123:0 -&is_inf -+inf::1 --inf::1 -abc::0 -1::0 -NaN::0 --1::0 -+inf:-:0 -+inf:+:1 --inf:-:1 --inf:+:0 --inf:-inf:1 --inf:+inf:0 -+inf:-inf:0 -+inf:+inf:1 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 -&blsft -abc:abc:NaN -+2:+2:8 -+1:+32:4294967296 -+1:+48:281474976710656 -+8:-2:NaN -# excercise base 10 -+12345:4:10:123450000 --1234:0:10:-1234 -+1234:0:10:1234 -+2:2:10:200 -+12:2:10:1200 -+1234:-3:10:NaN -1234567890123:12:10:1234567890123000000000000 --3:1:2:-6 --5:1:2:-10 --2:1:2:-4 --102533203:1:2:-205066406 -&brsft -abc:abc:NaN -+8:+2:2 -+4294967296:+32:1 -+281474976710656:+48:1 -+2:-2:NaN -# excercise base 10 --1234:0:10:-1234 -+1234:0:10:1234 -+200:2:10:2 -+1234:3:10:1 -+1234:2:10:12 -+1234:-3:10:NaN -310000:4:10:31 -12300000:5:10:123 -1230000000000:10:10:123 -09876123456789067890:12:10:9876123 -1234561234567890123:13:10:123456 -820265627:1:2:410132813 -# test shifting negative numbers in base 2 --15:1:2:-8 --14:1:2:-7 --13:1:2:-7 --12:1:2:-6 --11:1:2:-6 --10:1:2:-5 --9:1:2:-5 --8:1:2:-4 --7:1:2:-4 --6:1:2:-3 --5:1:2:-3 --4:1:2:-2 --3:1:2:-2 --2:1:2:-1 --1:1:2:-1 --1640531254:2:2:-410132814 --1640531254:1:2:-820265627 --820265627:1:2:-410132814 --205066405:1:2:-102533203 -&bsstr -+inf:inf --inf:-inf -1e+34:1e+34 -123.456E3:123456e+0 -100:1e+2 -bsstrabc:NaN --5:-5e+0 --100:-1e+2 -&numify -numifyabc:NaN -+inf:inf --inf:-inf -5:5 --5:-5 -100:100 --100:-100 -&bneg -bnegNaN:NaN -+inf:-inf --inf:inf -abd:NaN -0:0 -1:-1 --1:1 -+123456789:-123456789 --123456789:123456789 -&babs -babsNaN:NaN -+inf:inf --inf:inf -0:0 -1:1 --1:1 -+123456789:123456789 --123456789:123456789 -&bcmp -bcmpNaN:bcmpNaN: -bcmpNaN:0: -0:bcmpNaN: -0:0:0 --1:0:-1 -0:-1:1 -1:0:1 -0:1:-1 --1:1:-1 -1:-1:1 --1:-1:0 -1:1:0 -123:123:0 -123:12:1 -12:123:-1 --123:-123:0 --123:-12:-1 --12:-123:1 -123:124:-1 -124:123:1 --123:-124:1 --124:-123:-1 -100:5:1 --123456789:987654321:-1 -+123456789:-987654321:1 --987654321:123456789:-1 --inf:5432112345:-1 -+inf:5432112345:1 --inf:-5432112345:-1 -+inf:-5432112345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:1 --inf:+inf:-1 -5:inf:-1 -5:inf:-1 --5:-inf:1 --5:-inf:1 -# return undef -+inf:NaN: -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 -&badd -abc:abc:NaN -abc:0:NaN -+0:abc:NaN -+inf:-inf:NaN --inf:+inf:NaN -+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 -1:1:2 --1:0:-1 -0:-1:-1 --1:-1:-2 --1:+1:0 -+1:-1:0 -+9:+1:10 -+99:+1:100 -+999:+1:1000 -+9999:+1:10000 -+99999:+1:100000 -+999999:+1:1000000 -+9999999:+1:10000000 -+99999999:+1:100000000 -+999999999:+1:1000000000 -+9999999999:+1:10000000000 -+99999999999:+1:100000000000 -+10:-1:9 -+100:-1:99 -+1000:-1:999 -+10000:-1:9999 -+100000:-1:99999 -+1000000:-1:999999 -+10000000:-1:9999999 -+100000000:-1:99999999 -+1000000000:-1:999999999 -+10000000000:-1:9999999999 -+123456789:987654321:1111111110 --123456789:987654321:864197532 --123456789:-987654321:-1111111110 -+123456789:-987654321:-864197532 --1:10001:10000 --1:100001:100000 --1:1000001:1000000 --1:10000001:10000000 --1:100000001:100000000 --1:1000000001:1000000000 --1:10000000001:10000000000 --1:100000000001:100000000000 --1:1000000000001:1000000000000 --1:10000000000001:10000000000000 --1:-10001:-10002 --1:-100001:-100002 --1:-1000001:-1000002 --1:-10000001:-10000002 --1:-100000001:-100000002 --1:-1000000001:-1000000002 --1:-10000000001:-10000000002 --1:-100000000001:-100000000002 --1:-1000000000001:-1000000000002 --1:-10000000000001:-10000000000002 -&bsub -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:inf --inf:+inf:-inf -+inf:+inf:NaN --inf:-inf:NaN -+0:+0:0 -+1:+0:1 -+0:+1:-1 -+1:+1:0 --1:+0:-1 -+0:-1:1 --1:-1:0 --1:+1:-2 -+1:-1:2 -+9:+1:8 -+99:+1:98 -+999:+1:998 -+9999:+1:9998 -+99999:+1:99998 -+999999:+1:999998 -+9999999:+1:9999998 -+99999999:+1:99999998 -+999999999:+1:999999998 -+9999999999:+1:9999999998 -+99999999999:+1:99999999998 -+10:-1:11 -+100:-1:101 -+1000:-1:1001 -+10000:-1:10001 -+100000:-1:100001 -+1000000:-1:1000001 -+10000000:-1:10000001 -+100000000:-1:100000001 -+1000000000:-1:1000000001 -+10000000000:-1:10000000001 -+123456789:+987654321:-864197532 --123456789:+987654321:-1111111110 --123456789:-987654321:864197532 -+123456789:-987654321:1111111110 -10001:1:10000 -100001:1:100000 -1000001:1:1000000 -10000001:1:10000000 -100000001:1:100000000 -1000000001:1:1000000000 -10000000001:1:10000000000 -100000000001:1:100000000000 -1000000000001:1:1000000000000 -10000000000001:1:10000000000000 -10001:-1:10002 -100001:-1:100002 -1000001:-1:1000002 -10000001:-1:10000002 -100000001:-1:100000002 -1000000001:-1:1000000002 -10000000001:-1:10000000002 -100000000001:-1:100000000002 -1000000000001:-1:1000000000002 -10000000000001:-1:10000000000002 -&bmuladd -abc:abc:0:NaN -abc:+0:0:NaN -+0:abc:0:NaN -+0:0:abc:NaN -NaNmul:+inf:0:NaN -NaNmul:-inf:0:NaN --inf:NaNmul:0:NaN -+inf:NaNmul:0:NaN -+inf:+inf:0:inf -+inf:-inf:0:-inf --inf:+inf:0:-inf --inf:-inf:0:inf -+0:+0:0:0 -+0:+1:0:0 -+1:+0:0:0 -+0:-1:0:0 --1:+0:0:0 -123456789123456789:0:0:0 -0:123456789123456789:0:0 --1:-1:0:1 --1:-1:0:1 --1:+1:0:-1 -+1:-1:0:-1 -+1:+1:0:1 -+2:+3:0:6 --2:+3:0:-6 -+2:-3:0:-6 --2:-3:0:6 -111:111:0:12321 -10101:10101:0:102030201 -1001001:1001001:0:1002003002001 -100010001:100010001:0:10002000300020001 -10000100001:10000100001:0:100002000030000200001 -11111111111:9:0:99999999999 -22222222222:9:0:199999999998 -33333333333:9:0:299999999997 -44444444444:9:0:399999999996 -55555555555:9:0:499999999995 -66666666666:9:0:599999999994 -77777777777:9:0:699999999993 -88888888888:9:0:799999999992 -99999999999:9:0:899999999991 -11111111111:9:1:100000000000 -22222222222:9:1:199999999999 -33333333333:9:1:299999999998 -44444444444:9:1:399999999997 -55555555555:9:1:499999999996 -66666666666:9:1:599999999995 -77777777777:9:1:699999999994 -88888888888:9:1:799999999993 -99999999999:9:1:899999999992 --3:-4:-5:7 -3:-4:-5:-17 --3:4:-5:-17 -3:4:-5:7 --3:4:5:-7 -3:-4:5:-7 -9999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890 -2:3:12345678901234567890:12345678901234567896 -&bmul -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 -+0:-1:0 --1:+0:0 -123456789123456789:0:0 -0:123456789123456789:0 --1:-1:1 --1:+1:-1 -+1:-1:-1 -+1:+1:1 -+2:+3:6 --2:+3:-6 -+2:-3:-6 --2:-3:6 -111:111:12321 -10101:10101:102030201 -1001001:1001001:1002003002001 -100010001:100010001:10002000300020001 -10000100001:10000100001:100002000030000200001 -11111111111:9:99999999999 -22222222222:9:199999999998 -33333333333:9:299999999997 -44444444444:9:399999999996 -55555555555:9:499999999995 -66666666666:9:599999999994 -77777777777:9:699999999993 -88888888888:9:799999999992 -99999999999:9:899999999991 -+25:+25:625 -+12345:+12345:152399025 -+99999:+11111:1111088889 -9999:10000:99990000 -99999:100000:9999900000 -999999:1000000:999999000000 -9999999:10000000:99999990000000 -99999999:100000000:9999999900000000 -999999999:1000000000:999999999000000000 -9999999999:10000000000:99999999990000000000 -99999999999:100000000000:9999999999900000000000 -999999999999:1000000000000:999999999999000000000000 -9999999999999:10000000000000:99999999999990000000000000 -99999999999999:100000000000000:9999999999999900000000000000 -999999999999999:1000000000000000:999999999999999000000000000000 -9999999999999999:10000000000000000:99999999999999990000000000000000 -99999999999999999:100000000000000000:9999999999999999900000000000000000 -999999999999999999:1000000000000000000:999999999999999999000000000000000000 -9999999999999999999:10000000000000000000:99999999999999999990000000000000000000 -&bdiv-list -100:20:5,0 -4095:4095:1,0 --4095:-4095:1,0 -4095:-4095:-1,0 --4095:4095:-1,0 -123:2:61,1 -9:5:1,4 -9:4:2,1 -# inf handling and general remainder -5:8:0,5 -0:8:0,0 -11:2:5,1 -11:-2:-5,-1 --11:2:-5,1 -# see table in documentation in MBI -0:inf:0,0 -0:-inf:0,0 -5:inf:0,5 -5:-inf:0,5 --5:inf:0,-5 --5:-inf:0,-5 -inf:5:inf,0 --inf:5:-inf,0 -inf:-5:-inf,0 --inf:-5:inf,0 -5:5:1,0 --5:-5:1,0 -inf:inf:NaN,NaN --inf:-inf:NaN,NaN --inf:inf:NaN,NaN -inf:-inf:NaN,NaN -8:0:inf,8 -inf:0:inf,inf -# exceptions to reminder rule --8:0:-inf,-8 --inf:0:-inf,-inf -0:0:NaN,NaN -# test the shortcut in Calc if @$x == @$yorg -1234567812345678:123456712345678:10,688888898 -12345671234567:1234561234567:10,58888897 -123456123456:12345123456:10,4888896 -1234512345:123412345:10,388895 -1234567890999999999:1234567890:1000000000,999999999 -1234567890000000000:1234567890:1000000000,0 -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 -1:abc:NaN -0:0:NaN -# inf handling (see table in doc) -0:inf:0 -0:-inf:0 -5:inf:0 -5:-inf:0 --5:inf:0 --5:-inf:0 -inf:5:inf --inf:5:-inf -inf:-5:-inf --inf:-5:inf -5:5:1 --5:-5:1 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:inf -inf:0:inf --8:0:-inf --inf:0:-inf -0:0:NaN -11:2:5 --11:-2:5 --11:2:-5 -11:-2:-5 -0:1:0 -0:-1:0 -1:1:1 --1:-1:1 -1:-1:-1 --1:1:-1 -1:2:0 -2:1:2 -1:26:0 -1000000000:9:111111111 -2000000000:9:222222222 -3000000000:9:333333333 -4000000000:9:444444444 -5000000000:9:555555555 -6000000000:9:666666666 -7000000000:9:777777777 -8000000000:9:888888888 -9000000000:9:1000000000 -35500000:113:314159 -71000000:226:314159 -106500000:339:314159 -1000000000:3:333333333 -+10:+5:2 -+100:+4:25 -+1000:+8:125 -+10000:+16:625 -999999999999:9:111111111111 -999999999999:99:10101010101 -999999999999:999:1001001001 -999999999999:9999:100010001 -999999999999999:99999:10000100001 -+1111088889:99999:11111 --5:-3:1 --5:3:-1 -4:3:1 -4:-3:-1 -1:3:0 -1:-3:0 --2:-3:0 --2:3:0 -8:3:2 --8:3:-2 -14:-3:-4 --14:3:-4 --14:-3:4 -14:3:4 -# bug in Calc with '99999' vs $BASE-1 -10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576 -# test the shortcut in Calc if @$x == @$yorg -1234567812345678:123456712345678:10 -12345671234567:1234561234567:10 -123456123456:12345123456:10 -1234512345:123412345:10 -1234567890999999999:1234567890:1000000000 -1234567890000000000:1234567890:1000000000 -1234567890999999999:9876543210:124999998 -1234567890000000000:9876543210:124999998 -96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199 -# bug up to v0.35 in Calc (--$q one too many) -84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999 -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 -abc:abc:NaN -abc:5:NaN -5:abc:NaN -# bmodinv Expected Results from normal use -1:5:1 -3:5:2 --2:5:2 -8:5033:4404 -1234567891:13:6 --1234567891:13:7 -324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902 -## bmodinv Error cases / useless use of function -3:-5:NaN -inf:5:NaN -5:inf:NaN --inf:5:NaN -5:-inf:NaN -&bmodpow -# format: number:exponent:modulus:result -# bmodpow Data errors -abc:abc:abc:NaN -5:abc:abc:NaN -abc:5:abc:NaN -abc:abc:5:NaN -5:5:abc:NaN -5:abc:5:NaN -abc:5:5:NaN -# bmodpow Expected results -0:0:2:1 -1:0:2:1 -0:0:1:0 -8:7:5032:3840 -8:-1:5033:4404 -98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 -# bmodpow Error cases -8:8:-5:NaN -8:-1:16:NaN -inf:5:13:NaN -5:inf:13:NaN -&bmod -# inf handling, see table in doc -0:inf:0 -0:-inf:0 -5:inf:5 -5:-inf:5 --5:inf:-5 --5:-inf:-5 -inf:5:0 --inf:5:0 -inf:-5:0 --inf:-5:0 -5:5:0 --5:-5:0 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:8 -inf:0:inf -# exceptions to reminder rule --inf:0:-inf --8:0:-8 -0:0:NaN -abc:abc:NaN -abc:1:abc:NaN -1:abc:NaN -0:0:NaN -0:1:0 -1:0:1 -0:-1:0 --1:0:-1 -1:1:0 --1:-1:0 -1:-1:0 --1:1:0 -1:2:1 -2:1:0 -1000000000:9:1 -2000000000:9:2 -3000000000:9:3 -4000000000:9:4 -5000000000:9:5 -6000000000:9:6 -7000000000:9:7 -8000000000:9:8 -9000000000:9:0 -35500000:113:33 -71000000:226:66 -106500000:339:99 -1000000000:3:1 -10:5:0 -100:4:0 -1000:8:0 -10000:16:0 -999999999999:9:0 -999999999999:99:0 -999999999999:999:0 -999999999999:9999:0 -999999999999999:99999:0 --9:+5:1 -+9:-5:-1 --9:-5:-4 --5:3:1 --2:3:1 -4:3:1 -1:3:1 --5:-3:-2 --2:-3:-2 -4:-3:-2 -1:-3:-2 -4095:4095:0 -100041000510123:3:0 -152403346:12345:4321 -9:5:4 -# test shortcuts in Calc -# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0 -1234:9:1 -123456:9:3 -12345678:9:0 -1234567891:9:1 -123456789123:9:6 -12345678912345:9:6 -1234567891234567:9:1 -123456789123456789:9:0 -1234:10:4 -123456:10:6 -12345678:10:8 -1234567891:10:1 -123456789123:10:3 -12345678912345:10:5 -1234567891234567:10:7 -123456789123456789:10:9 -1234:113:104 -123456:113:60 -12345678:113:89 -1234567891:113:64 -123456789123:113:95 -12345678912345:113:53 -1234567891234567:113:56 -123456789123456789:113:39 -# bug in bmod() not modifying the variable in place --629:5033:4404 -# bug in bmod() in Calc in the _div_use_div() shortcut code path, -# when X == X and X was big -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 -+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 -&band -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:0 -3:2:2 -+8:+2:0 -+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 -0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF -0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0x0xF0F0 -0x0F0F:0x0F0F:0x0x0F0F -0xF0F0F0:0xF0F0F0:0x0xF0F0F0 -0x0F0F0F:0x0F0F0F:0x0x0F0F0F -0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 -0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F -0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F -0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F -&bior -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:3 -+8:+2:10 -+281474976710656:0:281474976710656 -+281474976710656:1:281474976710657 -+281474976710656:281474976710656:281474976710656 --2:-3:-1 --1:-1:-1 --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 -0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF -0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0:0xFFFF:0x0xFFFF -0:0xFFFFFF:0x0xFFFFFF -0:0xFFFFFFFF:0x0xFFFFFFFF -0:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xFFFF:0:0x0xFFFF -0xFFFFFF:0:0x0xFFFFFF -0xFFFFFFFF:0:0x0xFFFFFFFF -0xFFFFFFFFFF:0:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0x0xF0F0 -0x0F0F:0x0F0F:0x0x0F0F -0xF0F0:0x0F0F:0x0xFFFF -0xF0F0F0:0xF0F0F0:0x0xF0F0F0 -0x0F0F0F:0x0F0F0F:0x0x0F0F0F -0x0F0F0F:0xF0F0F0:0x0xFFFFFF -0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 -0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F -0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF -0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F -0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F -0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -&bxor -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:3 -+8:+2:10 -+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 -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 -0xFFFFFFFF:0xFFFFFFFF:0 -0xFFFFFFFFFF:0xFFFFFFFFFF:0 -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0 -0:0xFFFF:0x0xFFFF -0:0xFFFFFF:0x0xFFFFFF -0:0xFFFFFFFF:0x0xFFFFFFFF -0:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xFFFF:0:0x0xFFFF -0xFFFFFF:0:0x0xFFFFFF -0xFFFFFFFF:0:0x0xFFFFFFFF -0xFFFFFFFFFF:0:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0 -0x0F0F:0x0F0F:0 -0xF0F0:0x0F0F:0x0xFFFF -0xF0F0F0:0xF0F0F0:0 -0x0F0F0F:0x0F0F0F:0 -0x0F0F0F:0xF0F0F0:0x0xFFFFFF -0xF0F0F0F0:0xF0F0F0F0:0 -0x0F0F0F0F:0x0F0F0F0F:0 -0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF -0xF0F0F0F0F0:0xF0F0F0F0F0:0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0 -0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0 -0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -&bnot -abc:NaN -+0:-1 -+8:-9 -+281474976710656:-281474976710657 --1:0 --2:1 --12:11 -&digit -0:0:0 -12:0:2 -12:1:1 -123:0:3 -123:1:2 -123:2:1 -123:-1:1 -123:-2:2 -123:-3:3 -123456:0:6 -123456:1:5 -123456:2:4 -123456:3:3 -123456:4:2 -123456:5:1 -123456:-1:1 -123456:-2:2 -123456:-3:3 -100000:-3:0 -100000:0:0 -100000:1:0 -&mantissa -abc:NaN -1e4:1 -2e0:2 -123:123 --1:-1 --2:-2 -+inf:inf --inf:-inf -&exponent -abc:NaN -1e4:4 -2e0:0 -123:0 --1:0 --2:0 -0:1 -+inf:inf --inf:inf -&parts -abc:NaN,NaN -1e4:1,4 -2e0:2,0 -123:123,0 --1:-1,0 --2:-2,0 -0:0,1 -+inf:inf,inf --inf:-inf,inf -&bfac --1:NaN -NaNfac:NaN -+inf:inf --inf:NaN -0:1 -1:1 -2:2 -3:6 -4:24 -5:120 -6:720 -7:5040 -8:40320 -9:362880 -10:3628800 -11:39916800 -12:479001600 -20:2432902008176640000 -22:1124000727777607680000 -69:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000 -&bpow -abc:12:NaN -12:abc:NaN -0:0:1 -0:1:0 -0:2:0 -0:-1:inf -0:-2:inf -1:0:1 -1:1:1 -1:2:1 -1:3:1 -1:-1:1 -1:-2:1 -1:-3:1 -2:0:1 -2:1:2 -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: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 --1:1:-1 --1:2:1 --1:3:-1 --1:4:1 --1:5:-1 --1:-1:-1 --1:-2:1 --1:-3:-1 --1:-4:1 -10:2:100 -10:3:1000 -10:4:10000 -10:5:100000 -10:6:1000000 -10:7:10000000 -10:8:100000000 -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 -1:1 -0:1 -12345:5 -10000000000000000:17 --123:3 -215960156869840440586892398248:30 -&broot -# sqrt() -+0:2:0 -+1:2:1 --1:2:NaN -# -$x ** (1/2) => -$y, but not in froot() --123:2:NaN -+inf:2:inf --inf:2:NaN -2:2:1 --2:2:NaN -4:2:2 -9:2:3 -16:2:4 -100:2:10 -123:2:11 -15241:2:123 -144:2:12 -12:2:3 -0.49:2:0 -0.0049:2:0 -# invalid ones -1:NaN:NaN --1:NaN:NaN -0:NaN:NaN --inf:NaN:NaN -+inf:NaN:NaN -NaN:0:NaN -NaN:2:NaN -NaN:inf:NaN -NaN:inf:NaN -12:-inf:NaN -12:inf:NaN -+0:0:NaN -+1:0:NaN --1:0:NaN --2:0:NaN --123.45:0:NaN -+inf:0:NaN -12:1:12 --12:1:NaN -8:-1:NaN --8:-1:NaN -# cubic root -8:3:2 --8:3:NaN -# fourths root -16:4:2 -81:4:3 -# 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.t for more tests -&bsqrt -145:12 -144:12 -143:11 -16:4 -170:13 -169:13 -168:12 -4:2 -3:1 -2:1 -9:3 -12:3 -256:16 -100000000:10000 -4000000000000:2000000 -152399026:12345 -152399025:12345 -152399024:12344 -# 2 ** 64 => 2 ** 32 -18446744073709551616:4294967296 -84274086103068221283760416414557757:290299993288095377 -1:1 -0:0 --2:NaN --123:NaN -Nan:NaN -+inf:inf --inf:NaN -# see t/biglog.t for more tests -&bexp -NaN:NaN -inf:inf -1:2 -2:7 -&batan2 -NaN:1:10:NaN -NaN:NaN:10:NaN -1:NaN:10:NaN -inf:1:14:1 --inf:1:14:-1 -0:-inf:14:3 --1:-inf:14:-3 -1:-inf:14:3 -0:inf:14:0 -inf:-inf:14:2 --inf:-inf:14:-2 -# +- 0.78.... -inf:+inf:14:0 --inf:+inf:14:0 -1:5:13:0 -1:5:14:0 -0:0:10:0 -0:1:14:0 -0:2:14:0 -1:0:14:1 -5:0:14:1 --1:0:11:-1 --2:0:77:-1 -2:0:77:1 --1:5:14:0 -1:5:14:0 --1:8:14:0 -1:8:14:0 --1:1:14:0 -&bpi -77:3 -+0:3 -11:3 -# see t/bignok.t for more tests -&bnok -+inf:10:inf -NaN:NaN:NaN -NaN:1:NaN -1:NaN:NaN -1:1:1 -# k > n -1:2:0 -2:3:0 -# k < 0 -1:-2:0 -# 7 over 3 = 35 -7:3:35 -7:6:1 -100:90:17310309456440 -100:95:75287520 -&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 -123456:5:123450 -123456:6:123456 -+10123456789:5:10123000000 --10123456789:5:-10123000000 -+10123456789:9:10123456700 --10123456789:9:-10123456700 -+101234500:6:101234000 --101234500:6:-101234000 -#+101234500:-4:101234000 -#-101234500:-4:-101234000 -$round_mode('zero') -+20123456789:5:20123000000 --20123456789:5:-20123000000 -+20123456789:9:20123456800 --20123456789:9:-20123456800 -+201234500:6:201234000 --201234500:6:-201234000 -#+201234500:-4:201234000 -#-201234500:-4:-201234000 -+12345000:4:12340000 --12345000:4:-12340000 -$round_mode('+inf') -+30123456789:5:30123000000 --30123456789:5:-30123000000 -+30123456789:9:30123456800 --30123456789:9:-30123456800 -+301234500:6:301235000 --301234500:6:-301234000 -#+301234500:-4:301235000 -#-301234500:-4:-301234000 -+12345000:4:12350000 --12345000:4:-12340000 -$round_mode('-inf') -+40123456789:5:40123000000 --40123456789:5:-40123000000 -+40123456789:9:40123456800 --40123456789:9:-40123456800 -+401234500:6:401234000 -+401234500:6:401234000 -#-401234500:-4:-401235000 -#-401234500:-4:-401235000 -+12345000:4:12340000 --12345000:4:-12350000 -$round_mode('odd') -+50123456789:5:50123000000 --50123456789:5:-50123000000 -+50123456789:9:50123456800 --50123456789:9:-50123456800 -+501234500:6:501235000 --501234500:6:-501235000 -#+501234500:-4:501235000 -#-501234500:-4:-501235000 -+12345000:4:12350000 --12345000:4:-12350000 -$round_mode('even') -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601234000 --601234500:6:-601234000 -#+601234500:-4:601234000 -#-601234500:-4:-601234000 -#-601234500:-9:0 -#-501234500:-9:0 -#-601234500:-8:0 -#-501234500:-8:0 -+1234567:7:1234567 -+1234567:6:1234570 -+12345000:4:12340000 --12345000:4:-12340000 -$round_mode('common') -+60123456789:5:60123000000 -+60123199999:5:60123000000 -+60123299999:5:60123000000 -+60123399999:5:60123000000 -+60123499999:5:60123000000 -+60123500000:5:60124000000 -+60123600000:5:60124000000 -+60123700000:5:60124000000 -+60123800000:5:60124000000 -+60123900000:5:60124000000 --60123456789:5:-60123000000 --60123199999:5:-60123000000 --60123299999:5:-60123000000 --60123399999:5:-60123000000 --60123499999:5:-60123000000 --60123500000:5:-60124000000 --60123600000:5:-60124000000 --60123700000:5:-60124000000 --60123800000:5:-60124000000 --60123900000:5:-60124000000 -&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 --2: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 -2:2 -3:3 -abc:NaN -&as_hex -128:0x80 --128:-0x80 -0:0x0 --0:0x0 -1:0x1 -0x123456789123456789:0x123456789123456789 -+inf:inf --inf:-inf -NaNas_hex:NaN -&as_bin -128:0b10000000 --128:-0b10000000 -0:0b0 --0:0b0 -1:0b1 -0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101 -0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001 -+inf:inf --inf:-inf -NaNas_bin:NaN diff --git a/lib/Math/BigInt/t/bigintpm.t b/lib/Math/BigInt/t/bigintpm.t deleted file mode 100644 index b4f5bf2fb1..0000000000 --- a/lib/Math/BigInt/t/bigintpm.t +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - unshift @INC, '../lib'; # for running manually - my $location = $0; $location =~ s/bigintpm.t//; - unshift @INC, $location; # to locate the testing files - chdir 't' if -d 't'; - plan tests => 3273 + 6; - } - -use Math::BigInt lib => 'Calc'; - -use vars qw ($scale $class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigInt"; -$CL = "Math::BigInt::Calc"; - -############################################################################# -# from_hex(), from_bin() and from_oct() tests - -my $x = Math::BigInt->from_hex('0xcafe'); -ok ($x, "51966", 'from_hex() works'); - -$x = Math::BigInt->from_hex('0xcafebabedead'); -ok ($x, "223195403574957", 'from_hex() works with long numbers'); - -$x = Math::BigInt->from_bin('0b1001'); -ok ($x, "9", 'from_bin() works'); - -$x = Math::BigInt->from_bin('0b1001100110011001100110011001'); -ok ($x, "161061273", 'from_bin() works with big numbers'); - -$x = Math::BigInt->from_oct('0775'); -ok ($x, "509", 'from_oct() works'); - -$x = Math::BigInt->from_oct('07777777777777711111111222222222'); -ok ($x, "9903520314281112085086151826", 'from_oct() works with big numbers'); - -############################################################################# -# all the other tests - -require 'bigintpm.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/bigints.t b/lib/Math/BigInt/t/bigints.t deleted file mode 100644 index de073e21e5..0000000000 --- a/lib/Math/BigInt/t/bigints.t +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bigints.t//i; - if ($ENV{PERL_CORE}) - { - @INC = qw(../t/lib); # testing with the core distribution - } - unshift @INC, '../lib'; # for testing manually - 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 => 51; - } - -# testing of Math::BigInt:Scalar (used by the testsuite), -# primarily for interface/api and not for the math functionality - -use Math::BigInt::Scalar; - -my $C = 'Math::BigInt::Scalar'; # pass classname to sub's - -# _new and _str -my $x = $C->_new("123"); my $y = $C->_new("321"); -ok (ref($x),'SCALAR'); ok ($C->_str($x),123); ok ($C->_str($y),321); - -# _add, _sub, _mul, _div - -ok ($C->_str($C->_add($x,$y)),444); -ok ($C->_str($C->_sub($x,$y)),123); -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($C->_div($x,$y)),123); - -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($x),39483); -ok ($C->_str($y),321); -my $z = $C->_new("2"); -ok ($C->_str($C->_add($x,$z)),39485); -my ($re,$rr) = $C->_div($x,$y); - -ok ($C->_str($re),123); ok ($C->_str($rr),2); - -# is_zero, _is_one, _one, _zero -ok ($C->_is_zero($x),0); -ok ($C->_is_one($x),0); - -ok ($C->_is_one($C->_one()),1); ok ($C->_is_one($C->_zero()),0); -ok ($C->_is_zero($C->_zero()),1); ok ($C->_is_zero($C->_one()),0); - -# is_odd, is_even -ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero()),0); -ok ($C->_is_even($C->_one()),0); ok ($C->_is_even($C->_zero()),1); - -# _digit -$x = $C->_new("123456789"); -ok ($C->_digit($x,0),9); -ok ($C->_digit($x,1),8); -ok ($C->_digit($x,2),7); -ok ($C->_digit($x,-1),1); -ok ($C->_digit($x,-2),2); -ok ($C->_digit($x,-3),3); - -# _copy -$x = $C->_new("12356"); -ok ($C->_str($C->_copy($x)),12356); - -# _acmp -$x = $C->_new("123456789"); -$y = $C->_new("987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); - -# _div -$x = $C->_new("3333"); $y = $C->_new("1111"); -ok ($C->_str( scalar $C->_div($x,$y)),3); -$x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); -ok ($C->_str($x),30); ok ($C->_str($y),3); -$x = $C->_new("123"); $y = $C->_new("1111"); -($x,$y) = $C->_div($x,$y); ok ($C->_str($x),0); ok ($C->_str($y),123); - -# _num -$x = $C->_new("12345"); $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,12345); - -# _len -$x = $C->_new("12345"); $x = $C->_len($x); ok (ref($x)||'',''); ok ($x,5); - -# _and, _or, _xor -$x = $C->_new("3"); $y = $C->_new("4"); ok ($C->_str( $C->_or($x,$y)),7); -$x = $C->_new("1"); $y = $C->_new("4"); ok ($C->_str( $C->_xor($x,$y)),5); -$x = $C->_new("7"); $y = $C->_new("3"); ok ($C->_str( $C->_and($x,$y)),3); - -# _pow -$x = $C->_new("2"); $y = $C->_new("4"); ok ($C->_str( $C->_pow($x,$y)),16); -$x = $C->_new("2"); $y = $C->_new("5"); ok ($C->_str( $C->_pow($x,$y)),32); -$x = $C->_new("3"); $y = $C->_new("3"); ok ($C->_str( $C->_pow($x,$y)),27); - - -# _check -$x = $C->_new("123456789"); -ok ($C->_check($x),0); -ok ($C->_check(123),'123 is not a reference'); - -# done - -1; - diff --git a/lib/Math/BigInt/t/biglog.t b/lib/Math/BigInt/t/biglog.t deleted file mode 100644 index 9478f7634e..0000000000 --- a/lib/Math/BigInt/t/biglog.t +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/perl -w - -# Test blog function (and bpow, since it uses blog), as well as bexp(). - -# It is too slow to be simple included in bigfltpm.inc, where it would get -# executed 3 times. One time would be under BareCalc, which shouldn't make any -# difference since there is no CALC->_log() function, and one time under a -# subclass, which *should* work. - -# But it is better to test the numerical functionality, instead of not testing -# it at all (which did lead to wrong answers for 0 < $x < 1 in blog() in -# versions up to v1.63, and for bsqrt($x) when $x << 1 for instance). - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/biglog.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../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 => 70; - } - -use Math::BigFloat; -use Math::BigInt; - -my $cl = "Math::BigInt"; - -############################################################################# -# test log($n) in BigInt (broken until 1.80) - -is ($cl->new(2)->blog(), '0', "blog(2)"); -is ($cl->new(288)->blog(), '5',"blog(288)"); -is ($cl->new(2000)->blog(), '7', "blog(2000)"); - -############################################################################# -# test exp($n) in BigInt - -is ($cl->new(1)->bexp(), '2', "bexp(1)"); -is ($cl->new(2)->bexp(), '7',"bexp(2)"); -is ($cl->new(3)->bexp(), '20', "bexp(3)"); - -############################################################################# -############################################################################# -# BigFloat tests - -############################################################################# -# test log(2, N) where N > 67 (broken until 1.82) - -$cl = "Math::BigFloat"; - -# These tests can take quite a while, but are nec. Maybe protect them with -# some alarm()? - -# this triggers the calculation and caching of ln(2): -ok ($cl->new(5)->blog(undef,71), -'1.6094379124341003746007593332261876395256013542685177219126478914741790'); - -# if the cache was correct, we should get this result, fast: -ok ($cl->new(2)->blog(undef,71), -'0.69314718055994530941723212145817656807550013436025525412068000949339362'); - -ok ($cl->new(10)->blog(undef,71), -'2.3025850929940456840179914546843642076011014886287729760333279009675726'); - -ok ($cl->new(21)->blog(undef,71), -'3.0445224377234229965005979803657054342845752874046106401940844835750742'); - -############################################################################# - -# These tests are now really fast, since they collapse to blog(10), basically -# Don't attempt to run them with older versions. You are warned. - -# $x < 0 => NaN -ok ($cl->new(-2)->blog(), 'NaN'); -ok ($cl->new(-1)->blog(), 'NaN'); -ok ($cl->new(-10)->blog(), 'NaN'); -ok ($cl->new(-2,2)->blog(), 'NaN'); - -my $ten = $cl->new(10)->blog(); - -# 10 is cached (up to 75 digits) -ok ($cl->new(10)->blog(), '2.302585092994045684017991454684364207601'); - -# 0.1 is using the cached value for log(10), too - -ok ($cl->new(0.1)->blog(), -$ten); -ok ($cl->new(0.01)->blog(), -$ten * 2); -ok ($cl->new(0.001)->blog(), -$ten * 3); -ok ($cl->new(0.0001)->blog(), -$ten * 4); - -# also cached -ok ($cl->new(2)->blog(), '0.6931471805599453094172321214581765680755'); -ok ($cl->new(4)->blog(), $cl->new(2)->blog * 2); - -# These are still slow, so do them only to 10 digits - -ok ($cl->new('0.2')->blog(undef,10), '-1.609437912'); -ok ($cl->new('0.3')->blog(undef,10), '-1.203972804'); -ok ($cl->new('0.4')->blog(undef,10), '-0.9162907319'); -ok ($cl->new('0.5')->blog(undef,10), '-0.6931471806'); -ok ($cl->new('0.6')->blog(undef,10), '-0.5108256238'); -ok ($cl->new('0.7')->blog(undef,10), '-0.3566749439'); -ok ($cl->new('0.8')->blog(undef,10), '-0.2231435513'); -ok ($cl->new('0.9')->blog(undef,10), '-0.1053605157'); - -ok ($cl->new('9')->blog(undef,10), '2.197224577'); - -ok ($cl->new('10')->blog(10,10), '1.000000000'); -ok ($cl->new('20')->blog(20,10), '1.000000000'); -ok ($cl->new('100')->blog(100,10), '1.000000000'); - -ok ($cl->new('100')->blog(10,10), '2.000000000'); # 10 ** 2 == 100 -ok ($cl->new('400')->blog(20,10), '2.000000000'); # 20 ** 2 == 400 - -ok ($cl->new('4')->blog(2,10), '2.000000000'); # 2 ** 2 == 4 -ok ($cl->new('16')->blog(2,10), '4.000000000'); # 2 ** 4 == 16 - -ok ($cl->new('1.2')->bpow('0.3',10), '1.056219968'); -ok ($cl->new('10')->bpow('0.6',10), '3.981071706'); - -# blog should handle bigint input -is (Math::BigFloat::blog(Math::BigInt->new(100),10), 2, "blog(100)"); - -############################################################################# -# some integer results -is ($cl->new(2)->bpow(32)->blog(2), '32', "2 ** 32"); -is ($cl->new(3)->bpow(32)->blog(3), '32', "3 ** 32"); -is ($cl->new(2)->bpow(65)->blog(2), '65', "2 ** 65"); - -my $x = Math::BigInt->new( '777' ) ** 256; -my $base = Math::BigInt->new( '12345678901234' ); -is ($x->copy()->blog($base), 56, 'blog(777**256, 12345678901234)'); - -$x = Math::BigInt->new( '777' ) ** 777; -$base = Math::BigInt->new( '777' ); -is ($x->copy()->blog($base), 777, 'blog(777**777, 777)'); - -############################################################################# -# test for bug in bsqrt() not taking negative _e into account -test_bpow ('200','0.5',10, '14.14213562'); -test_bpow ('20','0.5',10, '4.472135955'); -test_bpow ('2','0.5',10, '1.414213562'); -test_bpow ('0.2','0.5',10, '0.4472135955'); -test_bpow ('0.02','0.5',10, '0.1414213562'); -test_bpow ('0.49','0.5',undef , '0.7'); -test_bpow ('0.49','0.5',10 , '0.7000000000'); -test_bpow ('0.002','0.5',10, '0.04472135955'); -test_bpow ('0.0002','0.5',10, '0.01414213562'); -test_bpow ('0.0049','0.5',undef,'0.07'); -test_bpow ('0.0049','0.5',10 , '0.07000000000'); -test_bpow ('0.000002','0.5',10, '0.001414213562'); -test_bpow ('0.021','0.5',10, '0.1449137675'); -test_bpow ('1.2','0.5',10, '1.095445115'); -test_bpow ('1.23','0.5',10, '1.109053651'); -test_bpow ('12.3','0.5',10, '3.507135583'); - -test_bpow ('9.9','0.5',10, '3.146426545'); -test_bpow ('9.86902225','0.5',10, '3.141500000'); -test_bpow ('9.86902225','0.5',undef, '3.1415'); - -test_bpow ('0.2','0.41',10, '0.5169187652'); - -############################################################################# -# test bexp() with cached results - -is ($cl->new(1)->bexp(), '2.718281828459045235360287471352662497757', 'bexp(1)'); -is ($cl->new(2)->bexp(40), $cl->new(1)->bexp(45)->bpow(2,40), 'bexp(2)'); - -is ($cl->new("12.5")->bexp(61), $cl->new(1)->bexp(65)->bpow(12.5,61), 'bexp(12.5)'); - -############################################################################# -# test bexp() with big values (non-cached) - -is ($cl->new(1)->bexp(100), - '2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427', - 'bexp(100)'); - -is ($cl->new("12.5")->bexp(91), $cl->new(1)->bexp(95)->bpow(12.5,91), - 'bexp(12.5) to 91 digits'); - -# all done -1; - -############################################################################# -sub test_bpow - { - my ($x,$y,$scale,$result) = @_; - - print "# Tried: $x->bpow($y,$scale);\n" - unless ok ($cl->new($x)->bpow($y,$scale),$result); - } - - diff --git a/lib/Math/BigInt/t/bigroot.t b/lib/Math/BigInt/t/bigroot.t deleted file mode 100644 index 41fee89970..0000000000 --- a/lib/Math/BigInt/t/bigroot.t +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/perl -w - -# Test broot function (and bsqrt() function, since it is used by broot()). - -# It is too slow to be simple included in bigfltpm.inc, where it would get -# executed 3 times. - -# But it is better to test the numerical functionality, instead of not testing -# it at all. - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/bigroot.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../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 => 4 * 2; - } - -use Math::BigFloat; -use Math::BigInt; - -my $cl = "Math::BigFloat"; -my $c = "Math::BigInt"; - -# 2 ** 240 = -# 1766847064778384329583297500742918515827483896875618958121606201292619776 - -# takes way too long -#test_broot ('2','240', 8, undef, '1073741824'); -#test_broot ('2','240', 9, undef, '106528681.3099908308759836475139583940127'); -#test_broot ('2','120', 9, undef, '10321.27324073880096577298929482324664787'); -#test_broot ('2','120', 17, undef, '133.3268493632747279600707813049418888729'); - -test_broot ('2','120', 8, undef, '32768'); -test_broot ('2','60', 8, undef, '181.0193359837561662466161566988413540569'); -test_broot ('2','60', 9, undef, '101.5936673259647663841091609134277286651'); -test_broot ('2','60', 17, undef, '11.54672461623965153271017217302844672562'); - -sub test_broot - { - my ($x,$n,$y,$scale,$result) = @_; - - my $s = $scale || 'undef'; - is ($cl->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $cl $x->bpow($n)->broot($y,$s) == $result"); - $result =~ s/\..*//; - is ($c->new($x)->bpow($n)->broot($y,$scale),$result, "Try: $c $x->bpow($n)->broot($y,$s) == $result"); - } - diff --git a/lib/Math/BigInt/t/calling.t b/lib/Math/BigInt/t/calling.t deleted file mode 100644 index 4789cc7357..0000000000 --- a/lib/Math/BigInt/t/calling.t +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/perl -w - -# test calling conventions, and :constant overloading - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/calling.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../lib lib); - } - else - { - 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"; - my $tests = 160; - plan tests => $tests; - } - -package Math::BigInt::Test; - -use Math::BigInt; -use vars qw/@ISA/; -@ISA = qw/Math::BigInt/; # child of MBI -use overload; - -package Math::BigFloat::Test; - -use Math::BigFloat; -use vars qw/@ISA/; -@ISA = qw/Math::BigFloat/; # child of MBI -use overload; - -package main; - -use Math::BigInt try => 'Calc'; -use Math::BigFloat; - -my ($x,$y,$z,$u); -my $version = '1.76'; # adjust manually to match latest release - -############################################################################### -# check whether op's accept normal strings, even when inherited by subclasses - -# do one positive and one negative test to avoid false positives by "accident" - -my ($func,@args,$ans,$rc,$class,$try); -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - next if /^#/; # skip comments - if (s/^&//) - { - $func = $_; - } - else - { - @args = split(/:/,$_,99); - $ans = pop @args; - foreach $class (qw/ - Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/) - { - $try = "'$args[0]'"; # quote it - $try = $args[0] if $args[0] =~ /'/; # already quoted - $try = '' if $args[0] eq ''; # undef, no argument - $try = "$class\->$func($try);"; - $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, $ans); - } - } - - } - -$class = 'Math::BigInt'; - -# XXX TODO this test does not work/fail. -# test whether use Math::BigInt qw/version/ works -#$try = "use $class ($version.'1');"; -#$try .= ' $x = $class->new(123); $x = "$x";'; -#eval $try; -#ok_undef ( $x ); # should result in error! - -# test whether fallback to calc works -$try = "use $class ($version,'try','foo, bar , ');"; -$try .= "$class\->config()->{lib};"; -$ans = eval $try; -ok ( $ans =~ /^Math::BigInt::(Fast)?Calc\z/, 1); - -# test whether constant works or not, also test for qw($version) -# bgcd() is present in subclass, too -$try = "use Math::BigInt ($version,'bgcd',':constant');"; -$try .= ' $x = 2**150; bgcd($x); $x = "$x";'; -$ans = eval $try; -ok ( $ans, "1427247692705959881058285969449495136382746624"); - -# test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc) -$try = "use $class ($version,'lib','Scalar');"; -$try .= ' $x = 2**10; $x = "$x";'; -$ans = eval $try; ok ( $ans, "1024"); -$try = "use $class ($version,'lib','$class\::Scalar');"; -$try .= ' $x = 2**10; $x = "$x";'; -$ans = eval $try; ok ( $ans, "1024"); - -# all done - -__END__ -&is_zero -1:0 -0:1 -&is_one -1:1 -0:0 -&is_positive -1:1 --1:0 -&is_negative -1:0 --1:1 -&is_nan -abc:1 -1:0 -&is_inf -inf:1 -0:0 -&bstr -5:5 -10:10 --10:-10 -abc:NaN -'+inf':inf -'-inf':-inf -&bsstr -1:1e+0 -0:0e+1 -2:2e+0 -200:2e+2 --5:-5e+0 --100:-1e+2 -abc:NaN -'+inf':inf -&babs --1:1 -1:1 -&bnot --2:1 -1:-2 -&bzero -:0 -&bnan -:NaN -abc:NaN -&bone -:1 -'+':1 -'-':-1 -&binf -:inf -'+':inf -'-':-inf diff --git a/lib/Math/BigInt/t/config.t b/lib/Math/BigInt/t/config.t deleted file mode 100644 index 3bc9d2efee..0000000000 --- a/lib/Math/BigInt/t/config.t +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - chdir 't' if -d 't'; - unshift @INC, '../lib'; # for running manually - plan tests => 55; - } - -# test whether Math::BigInt->config() and Math::BigFloat->config() works - -use Math::BigInt lib => 'Calc'; -use Math::BigFloat; - -my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; - -############################################################################## -# BigInt - -ok ($mbi->can('config')); - -my $cfg = $mbi->config(); - -ok (ref($cfg),'HASH'); - -is ($cfg->{lib},'Math::BigInt::Calc', 'lib'); -is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version'); -is ($cfg->{class},$mbi,'class'); -is ($cfg->{upgrade}||'','', 'upgrade'); -is ($cfg->{div_scale},40, 'div_Scale'); - -is ($cfg->{precision}||0,0, 'precision'); # should test for undef -is ($cfg->{accuracy}||0,0,'accuracy'); -is ($cfg->{round_mode},'even','round_mode'); - -is ($cfg->{trap_nan},0, 'trap_nan'); -is ($cfg->{trap_inf},0, 'trap_inf'); - -is ($mbi->config('lib'), 'Math::BigInt::Calc', 'config("lib")'); - -# can set via hash ref? -$cfg = $mbi->config( { trap_nan => 1 } ); -is ($cfg->{trap_nan},1, 'can set via hash ref'); - -# reset for later -$mbi->config( trap_nan => 0 ); - -############################################################################## -# BigFloat - -ok ($mbf->can('config')); - -$cfg = $mbf->config(); - -ok (ref($cfg),'HASH'); - -is ($cfg->{lib},'Math::BigInt::Calc', 'lib'); -is ($cfg->{with},'Math::BigInt::Calc', 'with'); -is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version'); -is ($cfg->{class},$mbf,'class'); -is ($cfg->{upgrade}||'','', 'upgrade'); -is ($cfg->{div_scale},40, 'div_Scale'); - -is ($cfg->{precision}||0,0, 'precision'); # should test for undef -is ($cfg->{accuracy}||0,0,'accuracy'); -is ($cfg->{round_mode},'even','round_mode'); - -is ($cfg->{trap_nan},0, 'trap_nan'); -is ($cfg->{trap_inf},0, 'trap_inf'); - -is ($mbf->config('lib'), 'Math::BigInt::Calc', 'config("lib")'); - -# can set via hash ref? -$cfg = $mbf->config( { trap_nan => 1 } ); -is ($cfg->{trap_nan},1, 'can set via hash ref'); - -# reset for later -$mbf->config( trap_nan => 0 ); - -############################################################################## -# test setting values - -my $test = { - trap_nan => 1, - trap_inf => 1, - accuracy => 2, - precision => 3, - round_mode => 'zero', - div_scale => '100', - upgrade => 'Math::BigInt::SomeClass', - downgrade => 'Math::BigInt::SomeClass', - }; - -my $c; - -foreach my $key (keys %$test) - { - # see if setting in MBI works - eval ( "$mbi\->config( $key => '$test->{$key}' );" ); - $c = $mbi->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}"); - $c = $mbf->config(); - # see if setting it in MBI leaves MBF alone - if (($c->{$key}||0) ne $test->{$key}) - { - is (1,1); - } - else - { - is ("$key eq $c->{$key}","$key ne $test->{$key}", "$key"); - } - - # see if setting in MBF works - eval ( "$mbf\->config( $key => '$test->{$key}' );" ); - $c = $mbf->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}"); - } - -############################################################################## -# test setting illegal keys (should croak) - -$@ = ""; my $never_reached = 0; -eval ("$mbi\->config( 'some_garbage' => 1 ); $never_reached = 1;"); -is ($never_reached,0); - -$@ = ""; $never_reached = 0; -eval ("$mbf\->config( 'some_garbage' => 1 ); $never_reached = 1;"); -is ($never_reached,0); - -# this does not work. Why? -#ok ($@ eq "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104", 1); - -# all tests done - diff --git a/lib/Math/BigInt/t/const_mbf.t b/lib/Math/BigInt/t/const_mbf.t deleted file mode 100644 index a73177edb6..0000000000 --- a/lib/Math/BigInt/t/const_mbf.t +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/perl -w - -# test BigFloat constants alone (w/o BigInt loading) - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/const_mbf.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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; - } - -use Math::BigFloat ':constant'; - -ok (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); - -# BigInt was not loadede with ':constant', so only floats are handled -ok (ref(2 ** 2),''); - diff --git a/lib/Math/BigInt/t/constant.t b/lib/Math/BigInt/t/constant.t deleted file mode 100644 index 3e69bae0f7..0000000000 --- a/lib/Math/BigInt/t/constant.t +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/constant.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 7; - } - -use Math::BigInt ':constant'; - -ok (2 ** 255,'57896044618658097711785492504343953926634992332820282019728792003956564819968'); - -{ - no warnings 'portable'; # protect against "non-portable" warnings -# hexadecimal constants -ok (0x123456789012345678901234567890, - Math::BigInt->new('0x123456789012345678901234567890')); -# binary constants -ok (0b01010100011001010110110001110011010010010110000101101101, - Math::BigInt->new( - '0b01010100011001010110110001110011010010010110000101101101')); -} - -use Math::BigFloat ':constant'; -ok (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); - -# stress-test Math::BigFloat->import() - -Math::BigFloat->import( qw/:constant/ ); -ok (1,1); - -Math::BigFloat->import( qw/:constant upgrade Math::BigRat/ ); -ok (1,1); - -Math::BigFloat->import( qw/upgrade Math::BigRat :constant/ ); -ok (1,1); - -# all tests done - diff --git a/lib/Math/BigInt/t/downgrade.t b/lib/Math/BigInt/t/downgrade.t deleted file mode 100644 index 25d672c50f..0000000000 --- a/lib/Math/BigInt/t/downgrade.t +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - unshift @INC, '../lib'; # for running manually - my $location = $0; $location =~ s/downgrade.t//; - unshift @INC, $location; # to locate the testing files - chdir 't' if -d 't'; - plan tests => 15; - } - -use Math::BigInt upgrade => 'Math::BigFloat'; -use Math::BigFloat downgrade => 'Math::BigInt', upgrade => 'Math::BigInt'; - -use vars qw ($scale $class $try $x $y $f @args $ans $ans1 $ans1_str $setup - $ECL $CL); -$class = "Math::BigInt"; -$CL = "Math::BigInt::Calc"; -$ECL = "Math::BigFloat"; - -# simplistic test for now -ok (Math::BigFloat->downgrade(),'Math::BigInt'); -ok (Math::BigFloat->upgrade(),'Math::BigInt'); - -# these downgrade -ok (ref(Math::BigFloat->new('inf')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-inf')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('NaN')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('0')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('1')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('10')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-10')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-10.0E1')),'Math::BigInt'); - -# bug until v1.67: -ok (Math::BigFloat->new('0.2E0'), '0.2'); -ok (Math::BigFloat->new('0.2E1'), '2'); -# until v1.67 resulted in 200: -ok (Math::BigFloat->new('0.2E2'), '20'); - -# disable, otherwise it screws calculations -Math::BigFloat->upgrade(undef); -ok (Math::BigFloat->upgrade()||'',''); - -Math::BigFloat->div_scale(20); # make it a bit faster -my $x = Math::BigFloat->new(2); # downgrades -# the following test upgrade for bsqrt() and also makes new() NOT downgrade -# for the bpow() side -ok (Math::BigFloat->bpow('2','0.5'),$x->bsqrt()); - -#require 'upgrade.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/inf_nan.t b/lib/Math/BigInt/t/inf_nan.t deleted file mode 100644 index 0e5294fe44..0000000000 --- a/lib/Math/BigInt/t/inf_nan.t +++ /dev/null @@ -1,355 +0,0 @@ -#!/usr/bin/perl -w - -# test inf/NaN handling all in one place -# Thanx to Jarkko for the excellent explanations and the tables - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/inf_nan.t//i; - if ($ENV{PERL_CORE}) - { - @INC = qw(../t/lib); # testing with the core distribution - } - unshift @INC, '../lib'; # for testing manually - 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"; - - # values groups operators classes tests - plan tests => 7 * 6 * 5 * 4 * 2 + - 7 * 6 * 2 * 4 * 1 # bmod -; -# see bottom: + 4 * 10; # 4 classes * 10 NaN == NaN tests - } - -use Math::BigInt; -use Math::BigFloat; -use Math::BigInt::Subclass; -use Math::BigFloat::Subclass; - -my @classes = - qw/Math::BigInt Math::BigFloat - Math::BigInt::Subclass Math::BigFloat::Subclass - /; - -my (@args,$x,$y,$z); - -# + -foreach (qw/ - -inf:-inf:-inf - -1:-inf:-inf - -0:-inf:-inf - 0:-inf:-inf - 1:-inf:-inf - inf:-inf:NaN - NaN:-inf:NaN - - -inf:-1:-inf - -1:-1:-2 - -0:-1:-1 - 0:-1:-1 - 1:-1:0 - inf:-1:inf - NaN:-1:NaN - - -inf:0:-inf - -1:0:-1 - -0:0:0 - 0:0:0 - 1:0:1 - inf:0:inf - NaN:0:NaN - - -inf:1:-inf - -1:1:0 - -0:1:1 - 0:1:1 - 1:1:2 - inf:1:inf - NaN:1:NaN - - -inf:inf:NaN - -1:inf:inf - -0:inf:inf - 0:inf:inf - 1:inf:inf - inf:inf:inf - NaN:inf:NaN - - -inf:NaN:NaN - -1:NaN:NaN - -0:NaN:NaN - 0:NaN:NaN - 1:NaN:NaN - inf:NaN:NaN - NaN:NaN:NaN - /) - { - @args = split /:/,$_; - for my $class (@classes) - { - $x = $class->new($args[0]); - $y = $class->new($args[1]); - $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 - my $r = $x->badd($y); - - is($x->bstr(),$args[2],"x $class $args[0] + $args[1]"); - is($x->bstr(),$args[2],"r $class $args[0] + $args[1]"); - } - } - -# - -foreach (qw/ - -inf:-inf:NaN - -1:-inf:inf - -0:-inf:inf - 0:-inf:inf - 1:-inf:inf - inf:-inf:inf - NaN:-inf:NaN - - -inf:-1:-inf - -1:-1:0 - -0:-1:1 - 0:-1:1 - 1:-1:2 - inf:-1:inf - NaN:-1:NaN - - -inf:0:-inf - -1:0:-1 - -0:0:-0 - 0:0:0 - 1:0:1 - inf:0:inf - NaN:0:NaN - - -inf:1:-inf - -1:1:-2 - -0:1:-1 - 0:1:-1 - 1:1:0 - inf:1:inf - NaN:1:NaN - - -inf:inf:-inf - -1:inf:-inf - -0:inf:-inf - 0:inf:-inf - 1:inf:-inf - inf:inf:NaN - NaN:inf:NaN - - -inf:NaN:NaN - -1:NaN:NaN - -0:NaN:NaN - 0:NaN:NaN - 1:NaN:NaN - inf:NaN:NaN - NaN:NaN:NaN - /) - { - @args = split /:/,$_; - for my $class (@classes) - { - $x = $class->new($args[0]); - $y = $class->new($args[1]); - $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 - my $r = $x->bsub($y); - - is($x->bstr(),$args[2],"x $class $args[0] - $args[1]"); - is($r->bstr(),$args[2],"r $class $args[0] - $args[1]"); - } - } - -# * -foreach (qw/ - -inf:-inf:inf - -1:-inf:inf - -0:-inf:NaN - 0:-inf:NaN - 1:-inf:-inf - inf:-inf:-inf - NaN:-inf:NaN - - -inf:-1:inf - -1:-1:1 - -0:-1:0 - 0:-1:-0 - 1:-1:-1 - inf:-1:-inf - NaN:-1:NaN - - -inf:0:NaN - -1:0:-0 - -0:0:-0 - 0:0:0 - 1:0:0 - inf:0:NaN - NaN:0:NaN - - -inf:1:-inf - -1:1:-1 - -0:1:-0 - 0:1:0 - 1:1:1 - inf:1:inf - NaN:1:NaN - - -inf:inf:-inf - -1:inf:-inf - -0:inf:NaN - 0:inf:NaN - 1:inf:inf - inf:inf:inf - NaN:inf:NaN - - -inf:NaN:NaN - -1:NaN:NaN - -0:NaN:NaN - 0:NaN:NaN - 1:NaN:NaN - inf:NaN:NaN - NaN:NaN:NaN - /) - { - @args = split /:/,$_; - for my $class (@classes) - { - $x = $class->new($args[0]); - $y = $class->new($args[1]); - $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 - $args[2] = '0' if $args[2] eq '-0'; # BigInt hasn't got -0 - my $r = $x->bmul($y); - - is($x->bstr(),$args[2],"x $class $args[0] * $args[1]"); - is($r->bstr(),$args[2],"r $class $args[0] * $args[1]"); - } - } - -# / -foreach (qw/ - -inf:-inf:NaN - -1:-inf:0 - -0:-inf:0 - 0:-inf:-0 - 1:-inf:-0 - inf:-inf:NaN - NaN:-inf:NaN - - -inf:-1:inf - -1:-1:1 - -0:-1:0 - 0:-1:-0 - 1:-1:-1 - inf:-1:-inf - NaN:-1:NaN - - -inf:0:-inf - -1:0:-inf - -0:0:NaN - 0:0:NaN - 1:0:inf - inf:0:inf - NaN:0:NaN - - -inf:1:-inf - -1:1:-1 - -0:1:-0 - 0:1:0 - 1:1:1 - inf:1:inf - NaN:1:NaN - - -inf:inf:NaN - -1:inf:-0 - -0:inf:-0 - 0:inf:0 - 1:inf:0 - inf:inf:NaN - NaN:inf:NaN - - -inf:NaN:NaN - -1:NaN:NaN - -0:NaN:NaN - 0:NaN:NaN - 1:NaN:NaN - inf:NaN:NaN - NaN:NaN:NaN - /) - { - @args = split /:/,$_; - for my $class (@classes) - { - $x = $class->new($args[0]); - $y = $class->new($args[1]); - $args[2] = '0' if $args[2] eq '-0'; # BigInt/Float hasn't got -0 - - my $t = $x->copy(); - my $tmod = $t->copy(); - - # bdiv in scalar context - my $r = $x->bdiv($y); - 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 - 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? - is($m->bstr(),$rem->bstr(),"m $class $args[0] % $args[1]"); - # bmod() return agrees with set value? - 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/isa.t b/lib/Math/BigInt/t/isa.t deleted file mode 100644 index adb80f9331..0000000000 --- a/lib/Math/BigInt/t/isa.t +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/isa.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 7; - } - -use Math::BigInt::Subclass; -use Math::BigFloat::Subclass; -use Math::BigInt; -use Math::BigFloat; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigInt::Subclass"; -$CL = "Math::BigInt::Calc"; - -# Check that a subclass is still considered a BigInt -ok ($class->new(123)->isa('Math::BigInt'),1); - -# ditto for plain Math::BigInt -ok (Math::BigInt->new(123)->isa('Math::BigInt'),1); - -# But Math::BigFloats aren't -ok (Math::BigFloat->new(123)->isa('Math::BigInt') || 0,0); - -# see what happens if we feed a Math::BigFloat into new() -$x = Math::BigInt->new(Math::BigFloat->new(123)); -ok (ref($x),'Math::BigInt'); -ok ($x->isa('Math::BigInt'),1); - -# ditto for subclass -$x = Math::BigInt->new(Math::BigFloat->new(123)); -ok (ref($x),'Math::BigInt'); -ok ($x->isa('Math::BigInt'),1); - diff --git a/lib/Math/BigInt/t/lib_load.t b/lib/Math/BigInt/t/lib_load.t deleted file mode 100644 index ff3972effa..0000000000 --- a/lib/Math/BigInt/t/lib_load.t +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 => 4; - } - -# 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'); - -# See that Math::BigFloat supports "only" -eval "Math::BigFloat->import('only' => 'Calc')"; -is (Math::BigFloat::config()->{lib}, 'Math::BigInt::Calc', '"only" worked'); - -# See that Math::BigFloat supports "try" -eval "Math::BigFloat->import('try' => 'BareCalc')"; -is (Math::BigFloat::config()->{lib}, 'Math::BigInt::BareCalc', '"try" worked'); - diff --git a/lib/Math/BigInt/t/mbf_ali.t b/lib/Math/BigInt/t/mbf_ali.t deleted file mode 100644 index 1ca43157e3..0000000000 --- a/lib/Math/BigInt/t/mbf_ali.t +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl -w - -# test that the new alias names work - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/mbf_ali.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 6; - } - -use Math::BigFloat; - -use vars qw/$x $CL/; - -$CL = 'Math::BigFloat'; - -require 'alias.inc'; - - diff --git a/lib/Math/BigInt/t/mbi_ali.t b/lib/Math/BigInt/t/mbi_ali.t deleted file mode 100644 index 402801733b..0000000000 --- a/lib/Math/BigInt/t/mbi_ali.t +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl -w - -# test that the new alias names work - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/mbi_ali.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 6; - } - -use Math::BigInt; - -use vars qw/$x $CL/; - -$CL = 'Math::BigInt'; - -require 'alias.inc'; - - diff --git a/lib/Math/BigInt/t/mbi_rand.t b/lib/Math/BigInt/t/mbi_rand.t deleted file mode 100644 index e2bf6637de..0000000000 --- a/lib/Math/BigInt/t/mbi_rand.t +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/perl -w - -use Test::More; -use strict; - -my $count; - -BEGIN - { - $| = 1; - if ($^O eq 'os390') { print "1..0\n"; exit(0) } # test takes too long there - unshift @INC, '../lib'; # for running manually - my $location = $0; $location =~ s/mbi_rand.t//; - unshift @INC, $location; # to locate the testing files - chdir 't' if -d 't'; - $count = 128; - plan tests => $count*4; - } - -use Math::BigInt; -my $c = 'Math::BigInt'; - -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" and send me the output - -my $seed = ($#ARGV == 0) ? $ARGV[0] : int(rand(1165537)); -print "# seed: $seed\n"; srand($seed); - -print "# lib: ", Math::BigInt->config()->{lib},"\n"; -if (Math::BigInt->config()->{lib} =~ /::Calc/) - { - print "# base len: ", scalar Math::BigInt::Calc->_base_len(),"\n"; - } - -my ($A,$B,$As,$Bs,$ADB,$AMB,$la,$lb); -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. It also means - # that we get more frequently equal numbers or other special cases. - 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()) - { - for (1..4) { is (1,1, 'skipped this test'); } next; - } - - # 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 "# ($A / $B, $A % $B ) = $ADB $AMB\n"; - - print "# seed $seed, ". join(' ',Math::BigInt::Calc->_base_len()),"\n". - "# tried $ADB * $B + $two*$AMB - $AMB\n" - unless is ($ADB*$B+$two*$AMB-$AMB,$As, "ADB * B + 2 * AMB - AMB == A"); - if (is ($ADB*$B/$B,$ADB, "ADB * B / B == ADB")) - { - print "# seed: $seed, \$ADB * \$B / \$B = ", $ADB * $B / $B, " != $ADB (\$B=$B)\n"; - if (Math::BigInt->config()->{lib} =~ /::Calc/) - { - print "# ADB->[-1]: ", $ADB->{value}->[-1], " B->[-1]: ", $B->{value}->[-1],"\n"; - } - } - # swap 'em and try this, too - # $X = ($B/$A)*$A + $B % $A; - ($ADB,$AMB) = $B->copy()->bdiv($A); - # print "check: $ADB $AMB"; - print "# seed $seed, ". join(' ',Math::BigInt::Calc->_base_len()),"\n". - "# tried $ADB * $A + $two*$AMB - $AMB\n" - unless is ($ADB*$A+$two*$AMB-$AMB,$Bs, "ADB * A + 2 * AMB - AMB == B"); - print "# +$two * $AMB = ",$ADB * $A + $two * $AMB,"\n"; - print "# -$AMB = ",$ADB * $A + $two * $AMB - $AMB,"\n"; - print "# seed $seed, \$ADB * \$A / \$A = ", $ADB * $A / $A, " != $ADB (\$A=$A)\n" - unless is ($ADB*$A/$A,$ADB, "ADB * A/A == ADB"); - } - diff --git a/lib/Math/BigInt/t/mbimbf.inc b/lib/Math/BigInt/t/mbimbf.inc deleted file mode 100644 index b057eee3ec..0000000000 --- a/lib/Math/BigInt/t/mbimbf.inc +++ /dev/null @@ -1,967 +0,0 @@ -# test rounding, accuracy, precicion and fallback, round_mode and mixing -# of classes - -# Make sure you always quote any bare floating-point values, lest 123.46 will -# be stringified to 123.4599999999 due to limited float prevision. - -use strict; -my ($x,$y,$z,$u,$rc); - -############################################################################### -# test defaults and set/get - -{ - no strict 'refs'; - ok_undef (${"$mbi\::accuracy"}); - ok_undef (${"$mbi\::precision"}); - ok_undef ($mbi->accuracy()); - ok_undef ($mbi->precision()); - ok (${"$mbi\::div_scale"},40); - ok (${"$mbi\::round_mode"},'even'); - ok ($mbi->round_mode(),'even'); - - ok_undef (${"$mbf\::accuracy"}); - ok_undef (${"$mbf\::precision"}); - ok_undef ($mbf->precision()); - ok_undef ($mbf->precision()); - ok (${"$mbf\::div_scale"},40); - ok (${"$mbf\::round_mode"},'even'); - ok ($mbf->round_mode(),'even'); -} - -# accessors -foreach my $class ($mbi,$mbf) - { - ok_undef ($class->accuracy()); - ok_undef ($class->precision()); - ok ($class->round_mode(),'even'); - ok ($class->div_scale(),40); - - ok ($class->div_scale(20),20); - $class->div_scale(40); ok ($class->div_scale(),40); - - ok ($class->round_mode('odd'),'odd'); - $class->round_mode('even'); ok ($class->round_mode(),'even'); - - ok ($class->accuracy(2),2); - $class->accuracy(3); ok ($class->accuracy(),3); - ok_undef ($class->accuracy(undef)); - - ok ($class->precision(2),2); - ok ($class->precision(-2),-2); - $class->precision(3); ok ($class->precision(),3); - ok_undef ($class->precision(undef)); - } - -{ - no strict 'refs'; - # accuracy - foreach (qw/5 42 -1 0/) - { - ok (${"$mbf\::accuracy"} = $_,$_); - ok (${"$mbi\::accuracy"} = $_,$_); - } - ok_undef (${"$mbf\::accuracy"} = undef); - ok_undef (${"$mbi\::accuracy"} = undef); - - # precision - foreach (qw/5 42 -1 0/) - { - ok (${"$mbf\::precision"} = $_,$_); - ok (${"$mbi\::precision"} = $_,$_); - } - ok_undef (${"$mbf\::precision"} = undef); - ok_undef (${"$mbi\::precision"} = undef); - - # fallback - foreach (qw/5 42 1/) - { - ok (${"$mbf\::div_scale"} = $_,$_); - ok (${"$mbi\::div_scale"} = $_,$_); - } - # illegal values are possible for fallback due to no accessor - - # round_mode - foreach (qw/odd even zero trunc +inf -inf/) - { - ok (${"$mbf\::round_mode"} = $_,$_); - ok (${"$mbi\::round_mode"} = $_,$_); - } - ${"$mbf\::round_mode"} = 'zero'; - ok (${"$mbf\::round_mode"},'zero'); - ok (${"$mbi\::round_mode"},'-inf'); # from above - - # reset for further tests - ${"$mbi\::accuracy"} = undef; - ${"$mbi\::precision"} = undef; - ${"$mbf\::div_scale"} = 40; -} - -# local copies -$x = $mbf->new('123.456'); -ok_undef ($x->accuracy()); -ok ($x->accuracy(5),5); -ok_undef ($x->accuracy(undef),undef); -ok_undef ($x->precision()); -ok ($x->precision(5),5); -ok_undef ($x->precision(undef),undef); - -{ - no strict 'refs'; - # see if MBF changes MBIs values - ok (${"$mbi\::accuracy"} = 42,42); - ok (${"$mbf\::accuracy"} = 64,64); - ok (${"$mbi\::accuracy"},42); # should be still 42 - ok (${"$mbf\::accuracy"},64); # should be now 64 -} - -############################################################################### -# see if creating a number under set A or P will round it - -{ - no strict 'refs'; - ${"$mbi\::accuracy"} = 4; - ${"$mbi\::precision"} = undef; - - ok ($mbi->new(123456),123500); # with A - ${"$mbi\::accuracy"} = undef; - ${"$mbi\::precision"} = 3; - ok ($mbi->new(123456),123000); # with P - - ${"$mbf\::accuracy"} = 4; - ${"$mbf\::precision"} = undef; - ${"$mbi\::precision"} = undef; - - ok ($mbf->new('123.456'),'123.5'); # with A - ${"$mbf\::accuracy"} = undef; - ${"$mbf\::precision"} = -1; - ok ($mbf->new('123.456'),'123.5'); # with P from MBF, not MBI! - - ${"$mbf\::precision"} = undef; # reset -} - -############################################################################### -# see if MBI leaves MBF's private parts alone - -{ - no strict 'refs'; - ${"$mbi\::precision"} = undef; ${"$mbf\::precision"} = undef; - ${"$mbi\::accuracy"} = 4; ${"$mbf\::accuracy"} = undef; - ok ($mbf->new('123.456'),'123.456'); - ${"$mbi\::accuracy"} = undef; # reset -} - -############################################################################### -# see if setting accuracy/precision actually rounds the number - -$x = $mbf->new('123.456'); $x->accuracy(4); ok ($x,'123.5'); -$x = $mbf->new('123.456'); $x->precision(-2); ok ($x,'123.46'); - -$x = $mbi->new(123456); $x->accuracy(4); ok ($x,123500); -$x = $mbi->new(123456); $x->precision(2); ok ($x,123500); - -############################################################################### -# test actual rounding via round() - -$x = $mbf->new('123.456'); -ok ($x->copy()->round(5),'123.46'); -ok ($x->copy()->round(4),'123.5'); -ok ($x->copy()->round(5,2),'NaN'); -ok ($x->copy()->round(undef,-2),'123.46'); -ok ($x->copy()->round(undef,2),120); - -$x = $mbi->new('123'); -ok ($x->round(5,2),'NaN'); - -$x = $mbf->new('123.45000'); -ok ($x->copy()->round(undef,-1,'odd'),'123.5'); - -# see if rounding is 'sticky' -$x = $mbf->new('123.4567'); -$y = $x->copy()->bround(); # no-op since nowhere A or P defined - -ok ($y,123.4567); -$y = $x->copy()->round(5); -ok ($y->accuracy(),5); -ok_undef ($y->precision()); # A has precedence, so P still unset -$y = $x->copy()->round(undef,2); -ok ($y->precision(),2); -ok_undef ($y->accuracy()); # P has precedence, so A still unset - -# see if setting A clears P and vice versa -$x = $mbf->new('123.4567'); -ok ($x,'123.4567'); -ok ($x->accuracy(4),4); -ok ($x->precision(-2),-2); # clear A -ok_undef ($x->accuracy()); - -$x = $mbf->new('123.4567'); -ok ($x,'123.4567'); -ok ($x->precision(-2),-2); -ok ($x->accuracy(4),4); # clear P -ok_undef ($x->precision()); - -# does copy work? -$x = $mbf->new(123.456); $x->accuracy(4); $x->precision(2); -$z = $x->copy(); ok_undef ($z->accuracy(),undef); ok ($z->precision(),2); - -# does $x->bdiv($y,d) work when $d > div_scale? -$x = $mbf->new('0.008'); $x->accuracy(8); - -for my $e ( 4, 8, 16, 32 ) - { - print "# Tried: $x->bdiv(3,$e)\n" - unless ok (scalar $x->copy()->bdiv(3,$e), '0.002' . ('6' x ($e-2)) . '7'); - } - -# does accuracy()/precision work on zeros? -foreach my $c ($mbi,$mbf) - { - $x = $c->bzero(); $x->accuracy(5); ok ($x->{_a},5); - $x = $c->bzero(); $x->precision(5); ok ($x->{_p},5); - $x = $c->new(0); $x->accuracy(5); ok ($x->{_a},5); - $x = $c->new(0); $x->precision(5); ok ($x->{_p},5); - - $x = $c->bzero(); $x->round(5); ok ($x->{_a},5); - $x = $c->bzero(); $x->round(undef,5); ok ($x->{_p},5); - $x = $c->new(0); $x->round(5); ok ($x->{_a},5); - $x = $c->new(0); $x->round(undef,5); ok ($x->{_p},5); - - # see if trying to increasing A in bzero() doesn't do something - $x = $c->bzero(); $x->{_a} = 3; $x->round(5); ok ($x->{_a},3); - } - -############################################################################### -# test whether an opp calls objectify properly or not (or at least does what -# it should do given non-objects, w/ or w/o objectify()) - -foreach my $c ($mbi,$mbf) - { -# ${"$c\::precision"} = undef; # reset -# ${"$c\::accuracy"} = undef; # reset - - ok ($c->new(123)->badd(123),246); - ok ($c->badd(123,321),444); - ok ($c->badd(123,$c->new(321)),444); - - ok ($c->new(123)->bsub(122),1); - ok ($c->bsub(321,123),198); - ok ($c->bsub(321,$c->new(123)),198); - - ok ($c->new(123)->bmul(123),15129); - ok ($c->bmul(123,123),15129); - ok ($c->bmul(123,$c->new(123)),15129); - -# ok ($c->new(15129)->bdiv(123),123); -# ok ($c->bdiv(15129,123),123); -# ok ($c->bdiv(15129,$c->new(123)),123); - - ok ($c->new(15131)->bmod(123),2); - ok ($c->bmod(15131,123),2); - ok ($c->bmod(15131,$c->new(123)),2); - - ok ($c->new(2)->bpow(16),65536); - ok ($c->bpow(2,16),65536); - ok ($c->bpow(2,$c->new(16)),65536); - - ok ($c->new(2**15)->brsft(1),2**14); - ok ($c->brsft(2**15,1),2**14); - ok ($c->brsft(2**15,$c->new(1)),2**14); - - ok ($c->new(2**13)->blsft(1),2**14); - ok ($c->blsft(2**13,1),2**14); - ok ($c->blsft(2**13,$c->new(1)),2**14); - } - -############################################################################### -# test wether operations round properly afterwards -# These tests are not complete, since they do not excercise every "return" -# statement in the op's. But heh, it's better than nothing... - -$x = $mbf->new('123.456'); -$y = $mbf->new('654.321'); -$x->{_a} = 5; # $x->accuracy(5) would round $x straightaway -$y->{_a} = 4; # $y->accuracy(4) would round $x straightaway - -$z = $x + $y; ok ($z,'777.8'); -$z = $y - $x; ok ($z,'530.9'); -$z = $y * $x; ok ($z,'80780'); -$z = $x ** 2; ok ($z,'15241'); -$z = $x * $x; ok ($z,'15241'); - -# not: $z = -$x; ok ($z,'-123.46'); ok ($x,'123.456'); -$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; ok ($z,62); -$x = $mbf->new(123456); $x->{_a} = 4; -$z = $x->copy; $z++; ok ($z,123500); - -$x = $mbi->new(123456); -$y = $mbi->new(654321); -$x->{_a} = 5; # $x->accuracy(5) would round $x straightaway -$y->{_a} = 4; # $y->accuracy(4) would round $x straightaway - -$z = $x + $y; ok ($z,777800); -$z = $y - $x; ok ($z,530900); -$z = $y * $x; ok ($z,80780000000); -$z = $x ** 2; ok ($z,15241000000); -# not yet: $z = -$x; ok ($z,-123460); ok ($x,123456); -$z = $x->copy; $z++; ok ($z,123460); -$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; ok ($z,62000); - -$x = $mbi->new(123400); $x->{_a} = 4; -ok ($x->bnot(),-123400); # not -1234001 - -# both babs() and bneg() don't need to round, since the input will already -# be rounded (either as $x or via new($string)), and they don't change the -# value. The two tests below peek at this by using _a (illegally) directly -$x = $mbi->new(-123401); $x->{_a} = 4; ok ($x->babs(),123401); -$x = $mbi->new(-123401); $x->{_a} = 4; ok ($x->bneg(),123401); - -# test fdiv rounding to A and R (bug in v1.48 and maybe earlier versions) -$mbf->round_mode('even'); -$x = $mbf->new('740.7')->fdiv('6',4,undef,'zero'); ok ($x,'123.4'); - -$x = $mbi->new('123456'); $y = $mbi->new('123456'); $y->{_a} = 6; -ok ($x->bdiv($y),1); ok ($x->{_a},6); # carried over - -$x = $mbi->new('123456'); $y = $mbi->new('123456'); $x->{_a} = 6; -ok ($x->bdiv($y),1); ok ($x->{_a},6); # carried over - -$x = $mbi->new('123456'); $y = $mbi->new('223456'); $y->{_a} = 6; -ok ($x->bdiv($y),0); ok ($x->{_a},6); # carried over - -$x = $mbi->new('123456'); $y = $mbi->new('223456'); $x->{_a} = 6; -ok ($x->bdiv($y),0); ok ($x->{_a},6); # carried over - -############################################################################### -# test that bop(0) does the same than bop(undef) - -$x = $mbf->new('1234567890'); -ok ($x->copy()->bsqrt(0),$x->copy()->bsqrt(undef)); -ok ($x->copy->bsqrt(0),'35136.41828644462161665823116758077037159'); - -ok_undef ($x->{_a}); - -# test that bsqrt() modifies $x and does not just return something else -# (especially under BareCalc) -$z = $x->bsqrt(); -ok ($z,$x); ok ($x,'35136.41828644462161665823116758077037159'); - -$x = $mbf->new('1.234567890123456789'); -ok ($x->copy()->bpow('0.5',0),$x->copy()->bpow('0.5',undef)); -ok ($x->copy()->bpow('0.5',0),$x->copy()->bsqrt(undef)); -ok ($x->copy()->bpow('2',0),'1.524157875323883675019051998750190521'); - -############################################################################### -# test (also under Bare) that bfac() rounds at last step - -ok ($mbi->new(12)->bfac(),'479001600'); -ok ($mbi->new(12)->bfac(2),'480000000'); -$x = $mbi->new(12); $x->accuracy(2); ok ($x->bfac(),'480000000'); -$x = $mbi->new(13); $x->accuracy(2); ok ($x->bfac(),'6200000000'); -$x = $mbi->new(13); $x->accuracy(3); ok ($x->bfac(),'6230000000'); -$x = $mbi->new(13); $x->accuracy(4); ok ($x->bfac(),'6227000000'); -# this does 1,2,3...9,10,11,12...20 -$x = $mbi->new(20); $x->accuracy(1); ok ($x->bfac(),'2000000000000000000'); - -############################################################################### -# test bsqrt) rounding to given A/P/R (bug prior to v1.60) -$x = $mbi->new('123456')->bsqrt(2,undef); ok ($x,'350'); # not 351 -$x = $mbi->new('3')->bsqrt(2,undef); ok ($x->accuracy(),2); - -$mbi->round_mode('even'); $x = $mbi->new('126025')->bsqrt(2,undef,'+inf'); -ok ($x,'360'); # not 355 nor 350 - -$x = $mbi->new('126025')->bsqrt(undef,2); ok ($x,'400'); # not 355 - - -############################################################################### -# test mixed arguments - -$x = $mbf->new(10); -$u = $mbf->new(2.5); -$y = $mbi->new(2); - -$z = $x + $y; ok ($z,12); ok (ref($z),$mbf); -$z = $x / $y; ok ($z,5); ok (ref($z),$mbf); -$z = $u * $y; ok ($z,5); ok (ref($z),$mbf); - -$y = $mbi->new(12345); -$z = $u->copy()->bmul($y,2,undef,'odd'); ok ($z,31000); -$z = $u->copy()->bmul($y,3,undef,'odd'); ok ($z,30900); -$z = $u->copy()->bmul($y,undef,0,'odd'); ok ($z,30863); -$z = $u->copy()->bmul($y,undef,1,'odd'); ok ($z,30863); -$z = $u->copy()->bmul($y,undef,2,'odd'); ok ($z,30860); -$z = $u->copy()->bmul($y,undef,3,'odd'); ok ($z,30900); -$z = $u->copy()->bmul($y,undef,-1,'odd'); ok ($z,30862.5); - -my $warn = ''; $SIG{__WARN__} = sub { $warn = shift; }; -# these should no longer warn, even tho '3.17' is a NaN in BigInt (>= returns -# now false, bug until v1.80) -$warn = ''; eval "\$z = 3.17 <= \$y"; ok ($z, ''); -print "# Got: '$warn'\n" unless -ok ($warn !~ /^Use of uninitialized value (\$y )?(in numeric le \(<=\) |)at/); -$warn = ''; eval "\$z = \$y >= 3.17"; ok ($z, ''); -print "# Got: '$warn'\n" unless -ok ($warn !~ /^Use of uninitialized value (\$y )?(in numeric ge \(>=\) |)at/); - -# XXX TODO breakage: -# $z = $y->copy()->bmul($u,2,0,'odd'); ok ($z,31000); -# $z = $y * $u; ok ($z,5); ok (ref($z),$mbi); -# $z = $y + $x; ok ($z,12); ok (ref($z),$mbi); -# $z = $y / $x; ok ($z,0); ok (ref($z),$mbi); - -############################################################################### -# rounding in bdiv with fallback and already set A or P - -{ - no strict 'refs'; - ${"$mbf\::accuracy"} = undef; - ${"$mbf\::precision"} = undef; - ${"$mbf\::div_scale"} = 40; -} - - $x = $mbf->new(10); $x->{_a} = 4; - ok ($x->bdiv(3),'3.333'); - ok ($x->{_a},4); # set's it since no fallback - -$x = $mbf->new(10); $x->{_a} = 4; $y = $mbf->new(3); -ok ($x->bdiv($y),'3.333'); -ok ($x->{_a},4); # set's it since no fallback - -# rounding to P of x -$x = $mbf->new(10); $x->{_p} = -2; -ok ($x->bdiv(3),'3.33'); - -# round in div with requested P -$x = $mbf->new(10); -ok ($x->bdiv(3,undef,-2),'3.33'); - -# round in div with requested P greater than fallback -{ - no strict 'refs'; - ${"$mbf\::div_scale"} = 5; - $x = $mbf->new(10); - ok ($x->bdiv(3,undef,-8),'3.33333333'); - ${"$mbf\::div_scale"} = 40; -} - -$x = $mbf->new(10); $y = $mbf->new(3); $y->{_a} = 4; -ok ($x->bdiv($y),'3.333'); -ok ($x->{_a},4); ok ($y->{_a},4); # set's it since no fallback -ok_undef ($x->{_p}); ok_undef ($y->{_p}); - -# rounding to P of y -$x = $mbf->new(10); $y = $mbf->new(3); $y->{_p} = -2; -ok ($x->bdiv($y),'3.33'); -ok ($x->{_p},-2); - ok ($y->{_p},-2); -ok_undef ($x->{_a}); ok_undef ($y->{_a}); - -############################################################################### -# test whether bround(-n) fails in MBF (undocumented in MBI) -eval { $x = $mbf->new(1); $x->bround(-2); }; -ok ($@ =~ /^bround\(\) needs positive accuracy/,1); - -# test whether rounding to higher accuracy is no-op -$x = $mbf->new(1); $x->{_a} = 4; -ok ($x,'1.000'); -$x->bround(6); # must be no-op -ok ($x->{_a},4); -ok ($x,'1.000'); - -$x = $mbi->new(1230); $x->{_a} = 3; -ok ($x,'1230'); -$x->bround(6); # must be no-op -ok ($x->{_a},3); -ok ($x,'1230'); - -# bround(n) should set _a -$x->bround(2); # smaller works -ok ($x,'1200'); -ok ($x->{_a},2); - -# bround(-n) is undocumented and only used by MBF -# bround(-n) should set _a -$x = $mbi->new(12345); -$x->bround(-1); -ok ($x,'12300'); -ok ($x->{_a},4); - -# bround(-n) should set _a -$x = $mbi->new(12345); -$x->bround(-2); -ok ($x,'12000'); -ok ($x->{_a},3); - -# bround(-n) should set _a -$x = $mbi->new(12345); $x->{_a} = 5; -$x->bround(-3); -ok ($x,'10000'); -ok ($x->{_a},2); - -# bround(-n) should set _a -$x = $mbi->new(12345); $x->{_a} = 5; -$x->bround(-4); -ok ($x,'0'); -ok ($x->{_a},1); - -# bround(-n) should be noop if n too big -$x = $mbi->new(12345); -$x->bround(-5); -ok ($x,'0'); # scale to "big" => 0 -ok ($x->{_a},0); - -# bround(-n) should be noop if n too big -$x = $mbi->new(54321); -$x->bround(-5); -ok ($x,'100000'); # used by MBF to round 0.0054321 at 0.0_6_00000 -ok ($x->{_a},0); - -# bround(-n) should be noop if n too big -$x = $mbi->new(54321); $x->{_a} = 5; -$x->bround(-6); -ok ($x,'100000'); # no-op -ok ($x->{_a},0); - -# bround(n) should set _a -$x = $mbi->new(12345); $x->{_a} = 5; -$x->bround(5); # must be no-op -ok ($x,'12345'); -ok ($x->{_a},5); - -# bround(n) should set _a -$x = $mbi->new(12345); $x->{_a} = 5; -$x->bround(6); # must be no-op -ok ($x,'12345'); - -$x = $mbf->new('0.0061'); $x->bfround(-2); ok ($x,'0.01'); -$x = $mbf->new('0.004'); $x->bfround(-2); ok ($x,'0.00'); -$x = $mbf->new('0.005'); $x->bfround(-2); ok ($x,'0.00'); - -$x = $mbf->new('12345'); $x->bfround(2); ok ($x,'12340'); -$x = $mbf->new('12340'); $x->bfround(2); ok ($x,'12340'); - -# MBI::bfround should clear A for negative P -$x = $mbi->new('1234'); $x->accuracy(3); $x->bfround(-2); -ok_undef ($x->{_a}); - -# test that bfround() and bround() work with large numbers - -$x = $mbf->new(1)->bdiv(5678,undef,-63); -ok ($x, '0.000176118351532229658330398027474462839027826699542092286016203'); - -$x = $mbf->new(1)->bdiv(5678,undef,-90); -ok ($x, '0.000176118351532229658330398027474462839027826699542092286016202888340965128566396618527651'); - -$x = $mbf->new(1)->bdiv(5678,80); -ok ($x, '0.00017611835153222965833039802747446283902782669954209228601620288834096512856639662'); - -############################################################################### -# rounding with already set precision/accuracy - -$x = $mbf->new(1); $x->{_p} = -5; -ok ($x,'1.00000'); - -# further rounding donw -ok ($x->bfround(-2),'1.00'); -ok ($x->{_p},-2); - -$x = $mbf->new(12345); $x->{_a} = 5; -ok ($x->bround(2),'12000'); -ok ($x->{_a},2); - -$x = $mbf->new('1.2345'); $x->{_a} = 5; -ok ($x->bround(2),'1.2'); -ok ($x->{_a},2); - -# mantissa/exponent format and A/P -$x = $mbf->new('12345.678'); $x->accuracy(4); -ok ($x,'12350'); ok ($x->{_a},4); ok_undef ($x->{_p}); - -#ok_undef ($x->{_m}->{_a}); ok_undef ($x->{_e}->{_a}); -#ok_undef ($x->{_m}->{_p}); ok_undef ($x->{_e}->{_p}); - -# check for no A/P in case of fallback -# result -$x = $mbf->new(100) / 3; -ok_undef ($x->{_a}); ok_undef ($x->{_p}); - -# result & reminder -$x = $mbf->new(100) / 3; ($x,$y) = $x->bdiv(3); -ok_undef ($x->{_a}); ok_undef ($x->{_p}); -ok_undef ($y->{_a}); ok_undef ($y->{_p}); - -############################################################################### -# math with two numbers with differen A and P - -$x = $mbf->new(12345); $x->accuracy(4); # '12340' -$y = $mbf->new(12345); $y->accuracy(2); # '12000' -ok ($x+$y,24000); # 12340+12000=> 24340 => 24000 - -$x = $mbf->new(54321); $x->accuracy(4); # '12340' -$y = $mbf->new(12345); $y->accuracy(3); # '12000' -ok ($x-$y,42000); # 54320+12300=> 42020 => 42000 - -$x = $mbf->new('1.2345'); $x->precision(-2); # '1.23' -$y = $mbf->new('1.2345'); $y->precision(-4); # '1.2345' -ok ($x+$y,'2.46'); # 1.2345+1.2300=> 2.4645 => 2.46 - -############################################################################### -# round should find and use proper class - -#$x = Foo->new(); -#ok ($x->round($Foo::accuracy),'a' x $Foo::accuracy); -#ok ($x->round(undef,$Foo::precision),'p' x $Foo::precision); -#ok ($x->bfround($Foo::precision),'p' x $Foo::precision); -#ok ($x->bround($Foo::accuracy),'a' x $Foo::accuracy); - -############################################################################### -# find out whether _find_round_parameters is doing what's it's supposed to do - -{ - no strict 'refs'; - ${"$mbi\::accuracy"} = undef; - ${"$mbi\::precision"} = undef; - ${"$mbi\::div_scale"} = 40; - ${"$mbi\::round_mode"} = 'odd'; -} - -$x = $mbi->new(123); -my @params = $x->_find_round_parameters(); -ok (scalar @params,1); # nothing to round - -@params = $x->_find_round_parameters(1); -ok (scalar @params,4); # a=1 -ok ($params[0],$x); # self -ok ($params[1],1); # a -ok_undef ($params[2]); # p -ok ($params[3],'odd'); # round_mode - -@params = $x->_find_round_parameters(undef,2); -ok (scalar @params,4); # p=2 -ok ($params[0],$x); # self -ok_undef ($params[1]); # a -ok ($params[2],2); # p -ok ($params[3],'odd'); # round_mode - -eval { @params = $x->_find_round_parameters(undef,2,'foo'); }; -ok ($@ =~ /^Unknown round mode 'foo'/,1); - -@params = $x->_find_round_parameters(undef,2,'+inf'); -ok (scalar @params,4); # p=2 -ok ($params[0],$x); # self -ok_undef ($params[1]); # a -ok ($params[2],2); # p -ok ($params[3],'+inf'); # round_mode - -@params = $x->_find_round_parameters(2,-2,'+inf'); -ok (scalar @params,1); # error, A and P defined -ok ($params[0],$x); # self - -{ - no strict 'refs'; - ${"$mbi\::accuracy"} = 1; - @params = $x->_find_round_parameters(undef,-2); - ok (scalar @params,1); # error, A and P defined - ok ($params[0],$x); # self - ok ($x->is_nan(),1); # and must be NaN - - ${"$mbi\::accuracy"} = undef; - ${"$mbi\::precision"} = 1; - @params = $x->_find_round_parameters(1,undef); - ok (scalar @params,1); # error, A and P defined - ok ($params[0],$x); # self - ok ($x->is_nan(),1); # and must be NaN - - ${"$mbi\::precision"} = undef; # reset -} - -############################################################################### -# test whether bone/bzero take additional A & P, or reset it etc - -foreach my $c ($mbi,$mbf) - { - $x = $c->new(2)->bzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->bone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->binf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->bnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - - $x = $c->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->bnan(); - ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->binf(); - ok_undef ($x->{_a}); ok_undef ($x->{_p}); - - $x = $c->new(2,1); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1); ok_undef ($x->{_a}); ok ($x->{_p},1); - - $x = $c->new(2,1)->bzero(); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1)->bzero(); ok_undef ($x->{_a}); ok ($x->{_p},1); - - $x = $c->new(2,1)->bone(); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1)->bone(); ok_undef ($x->{_a}); ok ($x->{_p},1); - - $x = $c->new(2); $x->bone('+',2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bone('+',undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); - $x = $c->new(2); $x->bone('-',2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bone('-',undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); - - $x = $c->new(2); $x->bzero(2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bzero(undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); - } - -############################################################################### -# test whether bone/bzero honour globals - -for my $c ($mbi,$mbf) - { - $c->accuracy(2); - $x = $c->bone(); ok ($x->accuracy(),2); - $x = $c->bzero(); ok ($x->accuracy(),2); - $c->accuracy(undef); - - $c->precision(-2); - $x = $c->bone(); ok ($x->precision(),-2); - $x = $c->bzero(); ok ($x->precision(),-2); - $c->precision(undef); - } - -############################################################################### -# check whether mixing A and P creates a NaN - -# new with set accuracy/precision and with parameters -{ - no strict 'refs'; - foreach my $c ($mbi,$mbf) - { - ok ($c->new(123,4,-3),'NaN'); # with parameters - ${"$c\::accuracy"} = 42; - ${"$c\::precision"} = 2; - ok ($c->new(123),'NaN'); # with globals - ${"$c\::accuracy"} = undef; - ${"$c\::precision"} = undef; - } -} - -# binary ops -foreach my $class ($mbi,$mbf) - { - foreach (qw/add sub mul pow mod/) - #foreach (qw/add sub mul div pow mod/) - { - my $try = "my \$x = $class->new(1234); \$x->accuracy(5); "; - $try .= "my \$y = $class->new(12); \$y->precision(-3); "; - $try .= "\$x->b$_(\$y);"; - $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, 'NaN'); - } - } - -# unary ops -foreach (qw/new bsqrt/) - { - my $try = 'my $x = $mbi->$_(1234,5,-3); '; - $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, 'NaN'); - } - -# see if $x->bsub(0) and $x->badd(0) really round -foreach my $class ($mbi,$mbf) - { - $x = $class->new(123); $class->accuracy(2); $x->bsub(0); - ok ($x,120); - $class->accuracy(undef); - $x = $class->new(123); $class->accuracy(2); $x->badd(0); - ok ($x,120); - $class->accuracy(undef); - } - -############################################################################### -# test whether shortcuts returning zero/one preserve A and P - -my ($ans1,$f,$a,$p,$xp,$yp,$xa,$ya,$try,$ans,@args); -my $CALC = Math::BigInt->config()->{lib}; -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - next if /^\s*(#|$)/; # skip comments and empty lines - if (s/^&//) - { - $f = $_; next; # function - } - @args = split(/:/,$_,99); - my $ans = pop(@args); - - ($x,$xa,$xp) = split (/,/,$args[0]); - $xa = $xa || ''; $xp = $xp || ''; - $try = "\$x = $mbi->new('$x'); "; - $try .= "\$x->accuracy($xa); " if $xa ne ''; - $try .= "\$x->precision($xp); " if $xp ne ''; - - ($y,$ya,$yp) = split (/,/,$args[1]); - $ya = $ya || ''; $yp = $yp || ''; - $try .= "\$y = $mbi->new('$y'); "; - $try .= "\$y->accuracy($ya); " if $ya ne ''; - $try .= "\$y->precision($yp); " if $yp ne ''; - - $try .= "\$x->$f(\$y);"; - - # print "trying $try\n"; - $rc = eval $try; - # convert hex/binary targets to decimal - if ($ans =~ /^(0x0x|0b0b)/) - { - $ans =~ s/^0[xb]//; - $ans = $mbi->new($ans)->bstr(); - } - print "# Tried: '$try'\n" if !ok ($rc, $ans); - # check internal state of number objects - is_valid($rc,$f) if ref $rc; - - # now check whether A and P are set correctly - # only one of $a or $p will be set (no crossing here) - $a = $xa || $ya; $p = $xp || $yp; - - # print "Check a=$a p=$p\n"; - # print "# Tried: '$try'\n"; - if ($a ne '') - { - if (!(ok ($x->{_a}, $a) && ok_undef ($x->{_p}))) - { - print "# Check: A=$a and P=undef\n"; - print "# Tried: '$try'\n"; - } - } - if ($p ne '') - { - if (!(ok ($x->{_p}, $p) && ok_undef ($x->{_a}))) - { - print "# Check: A=undef and P=$p\n"; - print "# Tried: '$try'\n"; - } - } - } - -# all done -1; - -############################################################################### -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return 1 if !defined $x; - ok ($x,'undef'); - print "# Called from ",join(' ',caller()),"\n"; - return 0; - } - -############################################################################### -# sub to check validity of a BigInt internally, to ensure that no op leaves a -# number object in an invalid state (f.i. "-0") - -sub is_valid - { - my ($x,$f) = @_; - - my $e = 0; # error? - # ok as reference? - $e = 'Not a reference' if !ref($x); - - # has ok sign? - $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" - if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; - - $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; - $e = $CALC->_check($x->{value}) if $e eq '0'; - - # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); - - ok (1,$e." after op '$f'"); - } - -# format is: -# x,A,P:x,A,P:result -# 123,,3 means 123 with precision 3 (A is undef) -# the A or P of the result is calculated automatically -__DATA__ -&badd -123,,:123,,:246 -123,3,:0,,:123 -123,,-3:0,,:123 -123,,:0,3,:123 -123,,:0,,-3:123 -&bmul -123,,:1,,:123 -123,3,:0,,:0 -123,,-3:0,,:0 -123,,:0,3,:0 -123,,:0,,-3:0 -123,3,:1,,:123 -123,,-3:1,,:123 -123,,:1,3,:123 -123,,:1,,-3:123 -1,3,:123,,:123 -1,,-3:123,,:123 -1,,:123,3,:123 -1,,:123,,-3:123 -&bdiv -123,,:1,,:123 -123,4,:1,,:123 -123,,:1,4,:123 -123,,:1,,-4:123 -123,,-4:1,,:123 -1,4,:123,,:0 -1,,:123,4,:0 -1,,:123,,-4:0 -1,,-4:123,,:0 -&band -1,,:3,,:1 -1234,1,:0,,:0 -1234,,:0,1,:0 -1234,,-1:0,,:0 -1234,,:0,,-1:0 -0xFF,,:0x10,,:0x0x10 -0xFF,2,:0xFF,,:250 -0xFF,,:0xFF,2,:250 -0xFF,,1:0xFF,,:250 -0xFF,,:0xFF,,1:250 -&bxor -1,,:3,,:2 -1234,1,:0,,:1000 -1234,,:0,1,:1000 -1234,,3:0,,:1000 -1234,,:0,,3:1000 -0xFF,,:0x10,,:239 -# 250 ^ 255 => 5 -0xFF,2,:0xFF,,:5 -0xFF,,:0xFF,2,:5 -0xFF,,1:0xFF,,:5 -0xFF,,:0xFF,,1:5 -# 250 ^ 4095 = 3845 => 3800 -0xFF,2,:0xFFF,,:3800 -# 255 ^ 4100 = 4347 => 4300 -0xFF,,:0xFFF,2,:4300 -0xFF,,2:0xFFF,,:3800 -# 255 ^ 4100 = 10fb => 4347 => 4300 -0xFF,,:0xFFF,,2:4300 -&bior -1,,:3,,:3 -1234,1,:0,,:1000 -1234,,:0,1,:1000 -1234,,3:0,,:1000 -1234,,:0,,3:1000 -0xFF,,:0x10,,:0x0xFF -# FF | FA = FF => 250 -250,2,:0xFF,,:250 -0xFF,,:250,2,:250 -0xFF,,1:0xFF,,:250 -0xFF,,:0xFF,,1:250 -&bpow -2,,:3,,:8 -2,,:0,,:1 -2,2,:0,,:1 -2,,:0,2,:1 diff --git a/lib/Math/BigInt/t/mbimbf.t b/lib/Math/BigInt/t/mbimbf.t deleted file mode 100644 index 1ac9adadbd..0000000000 --- a/lib/Math/BigInt/t/mbimbf.t +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/perl -w - -# test rounding, accuracy, precicion and fallback, round_mode and mixing -# of classes - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/mbimbf.t//i; - if ($ENV{PERL_CORE}) - { - @INC = qw(../lib); # testing with the core distribution - } - else - { - unshift @INC, '../lib'; # for testing manually - } - 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 => 684 - + 26; # own tests - } - -use Math::BigInt 1.70; -use Math::BigFloat 1.43; - -use vars qw/$mbi $mbf/; - -$mbi = 'Math::BigInt'; -$mbf = 'Math::BigFloat'; - -require 'mbimbf.inc'; - -# some tests that won't work with subclasses, since the things are only -# garantied in the Math::BigInt/BigFloat (unless subclass chooses to support -# this) - -Math::BigInt->round_mode('even'); # reset for tests -Math::BigFloat->round_mode('even'); # reset for tests - -ok ($Math::BigInt::rnd_mode,'even'); -ok ($Math::BigFloat::rnd_mode,'even'); - -my $x = eval '$mbi->round_mode("huhmbi");'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbi' at/); - -$x = eval '$mbf->round_mode("huhmbf");'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbf' at/); - -# old way (now with test for validity) -$x = eval '$Math::BigInt::rnd_mode = "huhmbi";'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbi' at/); -$x = eval '$Math::BigFloat::rnd_mode = "huhmbf";'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbf' at/); -# see if accessor also changes old variable -$mbi->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); -$mbf->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); - -foreach my $class (qw/Math::BigInt Math::BigFloat/) - { - ok ($class->accuracy(5),5); # set A - ok_undef ($class->precision()); # and now P must be cleared - ok ($class->precision(5),5); # set P - ok_undef ($class->accuracy()); # and now A must be cleared - } - -foreach my $class (qw/Math::BigInt Math::BigFloat/) - { - $class->accuracy(42); - my $x = $class->new(123); # $x gets A of 42, too! - ok ($x->accuracy(),42); # really? - ok ($x->accuracy(undef),42); # $x has no A, but the - # global is still in effect for $x - # so the return value of that operation should - # be 42, not undef - ok ($x->accuracy(),42); # so $x should still have A = 42 - $class->accuracy(undef); # reset for further tests - $class->precision(undef); - } -# bug with flog(Math::BigFloat,Math::BigInt) -$x = Math::BigFloat->new(100); -$x = $x->blog(Math::BigInt->new(10)); - -ok ($x,2); - -# bug until v1.88 for sqrt() with enough digits -for my $i (80,88,100) - { - $x = Math::BigFloat->new("1." . ("0" x $i) . "1"); - $x = $x->bsqrt; - ok ($x, 1); - } diff --git a/lib/Math/BigInt/t/nan_cmp.t b/lib/Math/BigInt/t/nan_cmp.t deleted file mode 100644 index ffe7b14b23..0000000000 --- a/lib/Math/BigInt/t/nan_cmp.t +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl -w - -# test that overloaded compare works when NaN are involved - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - chdir 't' if -d 't'; - unshift @INC, '../lib'; # for running manually - plan tests => 26; - } - -use Math::BigInt; -use Math::BigFloat; - -compare (Math::BigInt->bnan(), Math::BigInt->bone() ); -compare (Math::BigFloat->bnan(), Math::BigFloat->bone() ); - -sub compare - { - my ($nan, $one) = @_; - - is ($one, $one, '1 == 1'); - - is ($one != $nan, 1, "1 != NaN"); - is ($nan != $one, 1, "NaN != 1"); - is ($nan != $nan, 1, "NaN != NaN"); - - is ($nan == $one, '', "NaN == 1"); - is ($one == $nan, '', "1 == NaN"); - is ($nan == $nan, '', "NaN == NaN"); - - is ($nan <= $one, '', "NaN <= 1"); - is ($one <= $nan, '', "1 <= NaN"); - is ($nan <= $nan, '', "NaN <= NaN"); - - is ($nan >= $one, '', "NaN >= 1"); - is ($one >= $nan, '', "1 >= NaN"); - is ($nan >= $nan, '', "NaN >= NaN"); - } - diff --git a/lib/Math/BigInt/t/new_ovld.t b/lib/Math/BigInt/t/new_ovld.t deleted file mode 100644 index 08708dc557..0000000000 --- a/lib/Math/BigInt/t/new_ovld.t +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl -w - -# Math::BigFloat->new had a bug where it would assume any object is a -# BigInt which broke overloaded non-BigInts. - -use Test::More tests => 4; - - -package Overloaded::Num; - -use overload '0+' => sub { ${$_[0]} }, - fallback => 1; -sub new { - my($class, $num) = @_; - return bless \$num, $class; -} - - -package main; - -use Math::BigFloat; - -my $overloaded_num = Overloaded::Num->new(2.23); -is $overloaded_num, 2.23; - -my $bigfloat = Math::BigFloat->new($overloaded_num); -is $bigfloat, 2.23, 'BigFloat->new accepts overloaded numbers'; - -my $bigint = Math::BigInt->new(Overloaded::Num->new(3)); -is $bigint, 3, 'BigInt->new accepts overloaded numbers'; - -is( Math::BigFloat->new($bigint), 3, 'BigFloat from BigInt' ); diff --git a/lib/Math/BigInt/t/req_mbf0.t b/lib/Math/BigInt/t/req_mbf0.t deleted file mode 100644 index 90cd57cc9a..0000000000 --- a/lib/Math/BigInt/t/req_mbf0.t +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigFloat and then bzero() works - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbf0.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -require Math::BigFloat; -my $x = Math::BigFloat->bzero(); $x++; -is ($x,1, '$x is 1'); - -# all tests done - diff --git a/lib/Math/BigInt/t/req_mbf1.t b/lib/Math/BigInt/t/req_mbf1.t deleted file mode 100644 index b0b4aea810..0000000000 --- a/lib/Math/BigInt/t/req_mbf1.t +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigFloat and then bone() works - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbf1.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->bone(); ok ($x,1); - -# all tests done - diff --git a/lib/Math/BigInt/t/req_mbfa.t b/lib/Math/BigInt/t/req_mbfa.t deleted file mode 100644 index b2d2a07099..0000000000 --- a/lib/Math/BigInt/t/req_mbfa.t +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigFloat and then bnan() works - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbfa.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->bnan(1); ok ($x,'NaN'); - -# all tests done - diff --git a/lib/Math/BigInt/t/req_mbfi.t b/lib/Math/BigInt/t/req_mbfi.t deleted file mode 100644 index 2c0ec67b02..0000000000 --- a/lib/Math/BigInt/t/req_mbfi.t +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigFloat and then binf() works - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbfi.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->binf(); ok ($x,'inf'); - -# all tests done - diff --git a/lib/Math/BigInt/t/req_mbfn.t b/lib/Math/BigInt/t/req_mbfn.t deleted file mode 100644 index e3887d41de..0000000000 --- a/lib/Math/BigInt/t/req_mbfn.t +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigFloat and then new() works - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbfn.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->new(1); ++$x; ok ($x,2); - -# all tests done - diff --git a/lib/Math/BigInt/t/req_mbfw.t b/lib/Math/BigInt/t/req_mbfw.t deleted file mode 100644 index 10afc7a272..0000000000 --- a/lib/Math/BigInt/t/req_mbfw.t +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl -w - -# check that requiring BigFloat and then calling import() works - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/req_mbfw.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 3; - } - -# normal require that calls import automatically (we thus have MBI afterwards) -require Math::BigFloat; -my $x = Math::BigFloat->new(1); ++$x; -is ($x,2, '$x is 2'); - -like (Math::BigFloat->config()->{with}, qr/^Math::BigInt::(Fast)?Calc\z/, 'with ignored' ); - -# now override -Math::BigFloat->import ( with => 'Math::BigInt::Subclass' ); - -# the "with" argument is ignored -like (Math::BigFloat->config()->{with}, qr/^Math::BigInt::(Fast)?Calc\z/, 'with ignored' ); - -# all tests done - diff --git a/lib/Math/BigInt/t/require.t b/lib/Math/BigInt/t/require.t deleted file mode 100644 index 50831e611d..0000000000 --- a/lib/Math/BigInt/t/require.t +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/perl -w - -# check that simple requiring BigInt works - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/require.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -my ($x); - -require Math::BigInt; $x = Math::BigInt->new(1); ++$x; - -ok ($x||'undef',2); - -# all tests done - diff --git a/lib/Math/BigInt/t/round.t b/lib/Math/BigInt/t/round.t deleted file mode 100644 index 90c46758a7..0000000000 --- a/lib/Math/BigInt/t/round.t +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/perl -w - -# test rounding with non-integer A and P parameters - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/round.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 95; - } - -use Math::BigFloat; - -my $cf = 'Math::BigFloat'; -my $ci = 'Math::BigInt'; - -my $x = $cf->new('123456.123456'); - -# unary ops with A -_do_a($x, 'round', 3, '123000'); -_do_a($x, 'bfround', 3, '123500'); -_do_a($x, 'bfround', 2, '123460'); -_do_a($x, 'bfround', -2, '123456.12'); -_do_a($x, 'bfround', -3, '123456.123'); - -_do_a($x, 'bround', 4, '123500'); -_do_a($x, 'bround', 3, '123000'); -_do_a($x, 'bround', 2, '120000'); - -_do_a($x, 'bsqrt', 4, '351.4'); -_do_a($x, 'bsqrt', 3, '351'); -_do_a($x, 'bsqrt', 2, '350'); - -# setting P -_do_p($x, 'bsqrt', 2, '350'); -_do_p($x, 'bsqrt', -2, '351.36'); - -# binary ops -_do_2_a($x, 'bdiv', 2, 6, '61728.1'); -_do_2_a($x, 'bdiv', 2, 4, '61730'); -_do_2_a($x, 'bdiv', 2, 3, '61700'); - -_do_2_p($x, 'bdiv', 2, -6, '61728.061728'); -_do_2_p($x, 'bdiv', 2, -4, '61728.0617'); -_do_2_p($x, 'bdiv', 2, -3, '61728.062'); - -# all tests done - -############################################################################# - -sub _do_a - { - my ($x, $method, $A, $result) = @_; - - is ($x->copy->$method($A), $result, "$method($A)"); - is ($x->copy->$method($A.'.1'), $result, "$method(${A}.1)"); - is ($x->copy->$method($A.'.5'), $result, "$method(${A}.5)"); - is ($x->copy->$method($A.'.6'), $result, "$method(${A}.6)"); - is ($x->copy->$method($A.'.9'), $result, "$method(${A}.9)"); - } - -sub _do_p - { - my ($x, $method, $P, $result) = @_; - - is ($x->copy->$method(undef,$P), $result, "$method(undef,$P)"); - is ($x->copy->$method(undef,$P.'.1'), $result, "$method(undef,${P}.1)"); - is ($x->copy->$method(undef,$P.'.5'), $result, "$method(undef.${P}.5)"); - is ($x->copy->$method(undef,$P.'.6'), $result, "$method(undef,${P}.6)"); - is ($x->copy->$method(undef,$P.'.9'), $result, "$method(undef,${P}.9)"); - } - -sub _do_2_a - { - my ($x, $method, $y, $A, $result) = @_; - - my $cy = $cf->new($y); - - is ($x->copy->$method($cy,$A), $result, "$method($cy,$A)"); - is ($x->copy->$method($cy,$A.'.1'), $result, "$method($cy,${A}.1)"); - is ($x->copy->$method($cy,$A.'.5'), $result, "$method($cy,${A}.5)"); - is ($x->copy->$method($cy,$A.'.6'), $result, "$method($cy,${A}.6)"); - is ($x->copy->$method($cy,$A.'.9'), $result, "$method($cy,${A}.9)"); - } - -sub _do_2_p - { - my ($x, $method, $y, $P, $result) = @_; - - my $cy = $cf->new($y); - - is ($x->copy->$method($cy,undef,$P), $result, "$method(undef,$P)"); - is ($x->copy->$method($cy,undef,$P.'.1'), $result, "$method($cy,undef,${P}.1)"); - is ($x->copy->$method($cy,undef,$P.'.5'), $result, "$method($cy,undef.${P}.5)"); - is ($x->copy->$method($cy,undef,$P.'.6'), $result, "$method($cy,undef,${P}.6)"); - is ($x->copy->$method($cy,undef,$P.'.9'), $result, "$method($cy,undef,${P}.9)"); - } - diff --git a/lib/Math/BigInt/t/sub_ali.t b/lib/Math/BigInt/t/sub_ali.t deleted file mode 100644 index 93620a9d82..0000000000 --- a/lib/Math/BigInt/t/sub_ali.t +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/perl -w - -# test that the new alias names work - -use Test::More; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/sub_ali.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 6; - } - -use Math::BigInt::Subclass; - -use vars qw/$CL $x/; -$CL = 'Math::BigInt::Subclass'; - -require 'alias.inc'; - diff --git a/lib/Math/BigInt/t/sub_mbf.t b/lib/Math/BigInt/t/sub_mbf.t deleted file mode 100644 index 11f63ddc4a..0000000000 --- a/lib/Math/BigInt/t/sub_mbf.t +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -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 => 2308 - + 6; # + our own tests - } - -use Math::BigFloat::Subclass; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigFloat::Subclass"; -$CL = Math::BigFloat->config()->{lib}; # "Math::BigInt::Calc"; or FastCalc - -require 'bigfltpm.inc'; # perform same tests as bigfltpm - -############################################################################### -# Now do custom tests for Subclass itself -my $ms = $class->new(23); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); - -# Check that subclass is a Math::BigFloat, but not a Math::Bigint -ok ($ms->isa('Math::BigFloat'),1); -ok ($ms->isa('Math::BigInt') || 0,0); - -use Math::BigFloat; - -my $bf = Math::BigFloat->new(23); # same as other -$ms += $bf; -print "# Tried: \$ms += \$bf, got $ms" if !ok (46, $ms); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); -print "# Wrong class: ref(\$ms) was ".ref($ms) if !ok ($class, ref($ms)); diff --git a/lib/Math/BigInt/t/sub_mbi.t b/lib/Math/BigInt/t/sub_mbi.t deleted file mode 100644 index 7a6b1e2b26..0000000000 --- a/lib/Math/BigInt/t/sub_mbi.t +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/sub_mbi.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../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 => 3273 - + 5; # +5 own tests - } - -use Math::BigInt::Subclass; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigInt::Subclass"; -$CL = "Math::BigInt::Calc"; - -my $version = '0.02'; # for $VERSION tests, match current release (by hand!) - -require 'bigintpm.inc'; # perform same tests as bigintpm - -############################################################################### -# Now do custom tests for Subclass itself - -my $ms = $class->new(23); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); - -# Check that a subclass is still considered a BigInt -ok ($ms->isa('Math::BigInt'),1); - -use Math::BigInt; - -my $bi = Math::BigInt->new(23); # same as other -$ms += $bi; -print "# Tried: \$ms += \$bi, got $ms" if !ok (46, $ms); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); -print "# Wrong class: ref(\$ms) was ".ref($ms) if !ok ($class, ref($ms)); diff --git a/lib/Math/BigInt/t/sub_mif.t b/lib/Math/BigInt/t/sub_mif.t deleted file mode 100644 index cd0c863075..0000000000 --- a/lib/Math/BigInt/t/sub_mif.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/perl -w - -# test rounding, accuracy, precicion and fallback, round_mode and mixing -# of classes - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/sub_mif.t//i; - if ($ENV{PERL_CORE}) - { - @INC = qw(../t/lib); # testing with the core distribution - } - unshift @INC, '../lib'; # for testing manually - 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 => 684; - } - -use Math::BigInt::Subclass; -use Math::BigFloat::Subclass; - -use vars qw/$mbi $mbf/; - -$mbi = 'Math::BigInt::Subclass'; -$mbf = 'Math::BigFloat::Subclass'; - -require 'mbimbf.inc'; - diff --git a/lib/Math/BigInt/t/trap.t b/lib/Math/BigInt/t/trap.t deleted file mode 100644 index 94a7da4acb..0000000000 --- a/lib/Math/BigInt/t/trap.t +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/perl -w - -# test that config ( trap_nan => 1, trap_inf => 1) really works/dies - -use strict; -use Test::More; - -BEGIN - { - $| = 1; - chdir 't' if -d 't'; - unshift @INC, '../lib'; # for running manually - plan tests => 43; - } - -use Math::BigInt; -use Math::BigFloat; - -my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; -my ($cfg,$x); - -foreach my $class ($mbi, $mbf) - { - # can do and defaults are okay? - ok ($class->can('config'), 'can config()'); - is ($class->config()->{trap_nan}, 0, 'trap_nan defaults to 0'); - is ($class->config()->{trap_inf}, 0, 'trap_inf defaults to 0'); - - # can set? - $cfg = $class->config( trap_nan => 1 ); - is ($cfg->{trap_nan},1, 'trap_nan now true'); - - # also test that new() still works normally - eval ("\$x = \$class->new('42'); \$x->bnan();"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,42,'$x after new() never modified'); - - # can reset? - $cfg = $class->config( trap_nan => 0 ); - is ($cfg->{trap_nan}, 0, 'trap_nan disabled'); - - # can set? - $cfg = $class->config( trap_inf => 1 ); - is ($cfg->{trap_inf}, 1, 'trap_inf enabled'); - - eval ("\$x = \$class->new('4711'); \$x->binf();"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,4711,'$x after new() never modified'); - - eval ("\$x = \$class->new('inf');"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,4711,'$x after new() never modified'); - - eval ("\$x = \$class->new('-inf');"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,4711,'$x after new() never modified'); - - # +$x/0 => +inf - eval ("\$x = \$class->new('4711'); \$x->bdiv(0);"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,4711,'$x after new() never modified'); - - # -$x/0 => -inf - eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,'-815', '$x after new not modified'); - - $cfg = $class->config( trap_nan => 1 ); - # 0/0 => NaN - eval ("\$x = \$class->new('0'); \$x->bdiv(0);"); - like ($@, qr/^Tried to set/, 'died'); - is ($x,'0', '$x after new not modified'); - } - -############################################################################## -# BigInt - -$x = Math::BigInt->new(2); -eval ("\$x = \$mbi->new('0.1');"); -is ($x,2,'never modified since it dies'); -eval ("\$x = \$mbi->new('0a.1');"); -is ($x,2,'never modified since it dies'); - -############################################################################## -# BigFloat - -$x = Math::BigFloat->new(2); -eval ("\$x = \$mbf->new('0.1a');"); -is ($x,2,'never modified since it dies'); - -# all tests done - diff --git a/lib/Math/BigInt/t/upgrade.inc b/lib/Math/BigInt/t/upgrade.inc deleted file mode 100644 index 1160a21c6b..0000000000 --- a/lib/Math/BigInt/t/upgrade.inc +++ /dev/null @@ -1,1500 +0,0 @@ -# include this file into another for subclass testing - -# This file is nearly identical to bigintpm.t, except that certain results -# are _requird_ to be different due to "upgrading" or "promoting" to BigFloat. -# The reverse is not true, any unmarked results can be either BigInt or -# BigFloat, depending on how good the internal optimization is (e.g. it -# is usually desirable to have 2 ** 2 return a BigInt, not a BigFloat). - -# Results that are required to be BigFloat are marked with C<^> at the end. - -# Please note that the testcount goes up by two for each extra result marked -# with ^, since then we test whether it has the proper class and that it left -# the upgrade variable alone. - -my $version = ${"$class\::VERSION"}; - -############################################################################## -# for testing inheritance of _swap - -package Math::Foo; - -use Math::BigInt lib => $main::CL; -use vars qw/@ISA/; -@ISA = (qw/Math::BigInt/); - -use overload -# customized overload for sub, since original does not use swap there -'-' => sub { my @a = ref($_[0])->_swap(@_); - $a[0]->bsub($a[1])}; - -sub _swap - { - # a fake _swap, which reverses the params - my $self = shift; # for override in subclass - if ($_[2]) - { - my $c = ref ($_[0] ) || 'Math::Foo'; - return ( $_[0]->copy(), $_[1] ); - } - else - { - return ( Math::Foo->new($_[1]), $_[0] ); - } - } - -############################################################################## -package main; - -my $CALC = $class->config()->{lib}; ok ($CALC,$CL); - -my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class); - -while (<DATA>) - { - $_ =~ s/[\n\r]//g; # remove newlines - next if /^#/; # skip comments - if (s/^&//) - { - $f = $_; next; - } - elsif (/^\$/) - { - $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next; - } - - @args = split(/:/,$_,99); $ans = pop(@args); - $expected_class = $class; - if ($ans =~ /\^$/) - { - $expected_class = $ECL; $ans =~ s/\^$//; - } - $try = "\$x = $class->new(\"$args[0]\");"; - if ($f eq "bnorm") - { - $try = "\$x = $class->bnorm(\"$args[0]\");"; - # some is_xxx tests - } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "as_hex") { - $try .= '$x->as_hex();'; - } elsif ($f eq "as_bin") { - $try .= '$x->as_bin();'; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "binf") { - $try .= "\$x->binf('$args[1]');"; - } elsif ($f eq "bone") { - $try .= "\$x->bone('$args[1]');"; - # some unary ops - } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "length") { - $try .= '$x->length();'; - } elsif ($f eq "exponent"){ - # ->bstr() to see if an object is returned - $try .= '$x = $x->exponent()->bstr();'; - } elsif ($f eq "mantissa"){ - # ->bstr() to see if an object is returned - $try .= '$x = $x->mantissa()->bstr();'; - } elsif ($f eq "parts"){ - $try .= '($m,$e) = $x->parts();'; - # ->bstr() to see if an object is returned - $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;'; - $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;'; - $try .= '"$m,$e";'; - } else { - if ($args[1] !~ /\./) - { - $try .= "\$y = $class->new(\"$args[1]\");"; # BigInt - } - else - { - $try .= "\$y = $ECL->new(\"$args[1]\");"; # BigFloat - } - if ($f eq "bcmp") - { - $try .= '$x->bcmp($y);'; - } elsif ($f eq "bround") { - $try .= "$round_mode; \$x->bround(\$y);"; - } elsif ($f eq "broot") { - $try .= "\$x->broot(\$y);"; - } elsif ($f eq "bacmp"){ - $try .= '$x->bacmp($y);'; - } elsif ($f eq "badd"){ - $try .= '$x + $y;'; - } elsif ($f eq "bsub"){ - $try .= '$x - $y;'; - } elsif ($f eq "bmul"){ - $try .= '$x * $y;'; - } elsif ($f eq "bdiv"){ - $try .= '$x / $y;'; - } elsif ($f eq "bdiv-list"){ - $try .= 'join (",",$x->bdiv($y));'; - # overload via x= - } elsif ($f =~ /^.=$/){ - $try .= "\$x $f \$y;"; - # overload via x - } elsif ($f =~ /^.$/){ - $try .= "\$x $f \$y;"; - } elsif ($f eq "bmod"){ - $try .= '$x % $y;'; - } elsif ($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 "blsft"){ - if (defined $args[2]) - { - $try .= "\$x->blsft(\$y,$args[2]);"; - } - else - { - $try .= "\$x << \$y;"; - } - }elsif ($f eq "brsft"){ - if (defined $args[2]) - { - $try .= "\$x->brsft(\$y,$args[2]);"; - } - else - { - $try .= "\$x >> \$y;"; - } - }elsif ($f eq "band"){ - $try .= "\$x & \$y;"; - }elsif ($f eq "bior"){ - $try .= "\$x | \$y;"; - }elsif ($f eq "bxor"){ - $try .= "\$x ^ \$y;"; - }elsif ($f eq "bpow"){ - $try .= "\$x ** \$y;"; - }elsif ($f eq "digit"){ - $try = "\$x = $class->new('$args[0]'); \$x->digit($args[1]);"; - } else { warn "Unknown op '$f'"; } - } # end else all other ops - - $ans1 = eval $try; - # convert hex/binary targets to decimal - if ($ans =~ /^(0x0x|0b0b)/) - { - $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr(); - } - if ($ans eq "") - { - ok_undef ($ans1); - } - else - { - # print "try: $try ans: $ans1 $ans\n"; - print "# Tried: '$try'\n" if !ok ($ans1, $ans); - if ($expected_class ne $class) - { - ok (ref($ans1),$expected_class); # also checks that it really is ref! - ok ($Math::BigInt::upgrade,'Math::BigFloat'); # still okay? - } - } - # check internal state of number objects - is_valid($ans1,$f) if ref $ans1; - } # endwhile data tests -close DATA; - -my $warn = ''; $SIG{__WARN__} = sub { $warn = shift; }; - -# these should not warn -$warn = ''; eval "\$z = 3.17 <= \$y"; ok ($z, 1); ok ($warn, ''); -$warn = ''; eval "\$z = \$y >= 3.17"; ok ($z, 1); ok ($warn, ''); - -# all tests done - -1; - -############################################################################### -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return if !defined $x; - ok ($x,'undef'); - } - -############################################################################### -# sub to check validity of a BigInt internally, to ensure that no op leaves a -# number object in an invalid state (f.i. "-0") - -sub is_valid - { - my ($x,$f,$c) = @_; - - # The checks here are loosened a bit to allow BigInt or BigFloats to pass - - my $e = 0; # error? - # ok as reference? - # $e = "Not a reference to $c" if (ref($x) || '') ne $c; - - # has ok sign? - $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" - if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; - - $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; - #$e = $CALC->_check($x->{value}) if $e eq '0'; - - # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); - - ok (1,$e." after op '$f'"); - } - -__DATA__ -&.= -1234:-345:1234-345 -&+= -1:2:3 --1:-2:-3 -&-= -1:2:-1 --1:-2:1 -&*= -2:3:6 --1:5:-5 -&%= -100:3:1 -8:9:8 -&/= -100:3:33.33333333333333333333333333333333333333 --8:2:-4 -&|= -2:1:3 -&&= -5:7:5 -&^= -5:7:2 -&is_negative -0:0 --1:1 -1:0 -+inf:0 --inf:1 -NaNneg:0 -&is_positive -0:0 --1:0 -1:1 -+inf:1 --inf:0 -NaNneg:0 -&is_odd -abc:0 -0:0 -1:1 -3:1 --1:1 --3:1 -10000001:1 -10000002:0 -2:0 -120:0 -121:1 -&is_int -NaN:0 -inf:0 --inf:0 -1:1 -12:1 -123e12:1 -&is_even -abc:0 -0:1 -1:0 -3:0 --1:0 --3:0 -10000001:0 -10000002:1 -2:1 -120:1 -121:0 -&bacmp -+0:-0:0 -+0:+1:-1 --1:+1:0 -+1:-1:0 --1:+2:-1 -+2:-1:1 --123456789:+987654321:-1 -+123456789:-987654321:-1 -+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 -12.3:12.3^ -# binary input -0babc:NaN -0b123:NaN -0b0:0 --0b0:0 --0b1:-1 -0b0001:1 -0b001:1 -0b011:3 -0b101:5 -0b1001:9 -0b10001:17 -0b100001:33 -0b1000001:65 -0b10000001:129 -0b100000001:257 -0b1000000001:513 -0b10000000001:1025 -0b100000000001:2049 -0b1000000000001:4097 -0b10000000000001:8193 -0b100000000000001:16385 -0b1000000000000001:32769 -0b10000000000000001:65537 -0b100000000000000001:131073 -0b1000000000000000001:262145 -0b10000000000000000001:524289 -0b100000000000000000001:1048577 -0b1000000000000000000001:2097153 -0b10000000000000000000001:4194305 -0b100000000000000000000001:8388609 -0b1000000000000000000000001:16777217 -0b10000000000000000000000001:33554433 -0b100000000000000000000000001:67108865 -0b1000000000000000000000000001:134217729 -0b10000000000000000000000000001:268435457 -0b100000000000000000000000000001:536870913 -0b1000000000000000000000000000001:1073741825 -0b10000000000000000000000000000001:2147483649 -0b100000000000000000000000000000001:4294967297 -0b1000000000000000000000000000000001:8589934593 -0b10000000000000000000000000000000001:17179869185 -0b_101:NaN -0b1_0_1:5 -0b0_0_0_1:1 -# hex input --0x0:0 -0xabcdefgh:NaN -0x1234:4660 -0xabcdef:11259375 --0xABCDEF:-11259375 --0x1234:-4660 -0x12345678:305419896 -0x1_2_3_4_56_78:305419896 -0xa_b_c_d_e_f:11259375 -0x_123:NaN -0x9:9 -0x11:17 -0x21:33 -0x41:65 -0x81:129 -0x101:257 -0x201:513 -0x401:1025 -0x801:2049 -0x1001:4097 -0x2001:8193 -0x4001:16385 -0x8001:32769 -0x10001:65537 -0x20001:131073 -0x40001:262145 -0x80001:524289 -0x100001:1048577 -0x200001:2097153 -0x400001:4194305 -0x800001:8388609 -0x1000001:16777217 -0x2000001:33554433 -0x4000001:67108865 -0x8000001:134217729 -0x10000001:268435457 -0x20000001:536870913 -0x40000001:1073741825 -0x80000001:2147483649 -0x100000001:4294967297 -0x200000001:8589934593 -0x400000001:17179869185 -0x800000001:34359738369 -# inf input -inf:inf -+inf:inf --inf:-inf -0inf:NaN -# abnormal input -:NaN -abc:NaN - 1 a:NaN -1bcd2:NaN -11111b:NaN -+1z:NaN --1z:NaN -# only one underscore between two digits -_123:NaN -_123_:NaN -123_:NaN -1__23:NaN -1E1__2:NaN -1_E12:NaN -1E_12:NaN -1_E_12:NaN -+_1E12:NaN -+0_1E2:100 -+0_0_1E2:100 --0_0_1E2:-100 --0_0_1E+0_0_2:-100 -E1:NaN -E23:NaN -1.23E1:12.3^ -1.23E-1:0.123^ -# bug with two E's in number being valid -1e2e3:NaN -1e2r:NaN -1e2.0:NaN -# leading zeros -012:12 -0123:123 -01234:1234 -012345:12345 -0123456:123456 -01234567:1234567 -012345678:12345678 -0123456789:123456789 -01234567891:1234567891 -012345678912:12345678912 -0123456789123:123456789123 -01234567891234:1234567891234 -# normal input -0:0 -+0:0 -+00:0 -+000:0 -000000000000000000:0 --0:0 --0000:0 -+1:1 -+01:1 -+001:1 -+00000100000:100000 -123456789:123456789 --1:-1 --01:-1 --001:-1 --123456789:-123456789 --00000100000:-100000 -1_2_3:123 -10000000000E-1_0:1 -1E2:100 -1E1:10 -1E0:1 -1.23E2:123 -100E-1:10 -# floating point input -# .2e2:20 -1.E3:1000 -1.01E2:101 -1010E-1:101 --1010E0:-1010 --1010E1:-10100 -1234.00:1234 -# non-integer numbers --1010E-2:-10.1^ --1.01E+1:-10.1^ --1.01E-1:-0.101^ -&bnan -1:NaN -2:NaN -abc:NaN -&bone -2:+:1 -2:-:-1 -boneNaN:-:-1 -boneNaN:+:1 -2:abc:1 -3::1 -&binf -1:+:inf -2:-:-inf -3:abc:inf -&is_nan -123:0 -abc:1 -NaN:1 --123:0 -&is_inf -+inf::1 --inf::1 -abc::0 -1::0 -NaN::0 --1::0 -+inf:-:0 -+inf:+:1 --inf:-:1 --inf:+:0 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 -&blsft -abc:abc:NaN -+2:+2:8 -+1:+32:4294967296 -+1:+48:281474976710656 -+8:-2:NaN -# excercise base 10 -+12345:4:10:123450000 --1234:0:10:-1234 -+1234:0:10:1234 -+2:2:10:200 -+12:2:10:1200 -+1234:-3:10:NaN -1234567890123:12:10:1234567890123000000000000 -&brsft -abc:abc:NaN -+8:+2:2 -+4294967296:+32:1 -+281474976710656:+48:1 -+2:-2:NaN -# excercise base 10 --1234:0:10:-1234 -+1234:0:10:1234 -+200:2:10:2 -+1234:3:10:1 -+1234:2:10:12 -+1234:-3:10:NaN -310000:4:10:31 -12300000:5:10:123 -1230000000000:10:10:123 -09876123456789067890:12:10:9876123 -1234561234567890123:13:10:123456 -&bsstr -1e+34:1e+34 -123.456E3:123456e+0 -100:1e+2 -abc:NaN -&bneg -bnegNaN:NaN -+inf:-inf --inf:inf -abd:NaN -0:0 -1:-1 --1:1 -+123456789:-123456789 --123456789:123456789 -&babs -babsNaN:NaN -+inf:inf --inf:inf -0:0 -1:1 --1:1 -+123456789:123456789 --123456789:123456789 -&bcmp -bcmpNaN:bcmpNaN: -bcmpNaN:0: -0:bcmpNaN: -0:0:0 --1:0:-1 -0:-1:1 -1:0:1 -0:1:-1 --1:1:-1 -1:-1:1 --1:-1:0 -1:1:0 -123:123:0 -123:12:1 -12:123:-1 --123:-123:0 --123:-12:-1 --12:-123:1 -123:124:-1 -124:123:1 --123:-124:1 --124:-123:-1 -100:5:1 --123456789:987654321:-1 -+123456789:-987654321:1 --987654321:123456789:-1 --inf:5432112345:-1 -+inf:5432112345:1 --inf:-5432112345:-1 -+inf:-5432112345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:1 --inf:+inf:-1 -5:inf:-1 -5:inf:-1 --5:-inf:1 --5:-inf:1 -# return undef -+inf:NaN: -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 -&badd -abc:abc:NaN -abc:0:NaN -+0:abc:NaN -+inf:-inf:NaN --inf:+inf:NaN -+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 -1:1:2 --1:0:-1 -0:-1:-1 --1:-1:-2 --1:+1:0 -+1:-1:0 -+9:+1:10 -+99:+1:100 -+999:+1:1000 -+9999:+1:10000 -+99999:+1:100000 -+999999:+1:1000000 -+9999999:+1:10000000 -+99999999:+1:100000000 -+999999999:+1:1000000000 -+9999999999:+1:10000000000 -+99999999999:+1:100000000000 -+10:-1:9 -+100:-1:99 -+1000:-1:999 -+10000:-1:9999 -+100000:-1:99999 -+1000000:-1:999999 -+10000000:-1:9999999 -+100000000:-1:99999999 -+1000000000:-1:999999999 -+10000000000:-1:9999999999 -+123456789:987654321:1111111110 --123456789:987654321:864197532 --123456789:-987654321:-1111111110 -+123456789:-987654321:-864197532 -2:2.5:4.5^ --123:-1.5:-124.5^ --1.2:1:-0.2^ -&bsub -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:inf --inf:+inf:-inf -+inf:+inf:NaN --inf:-inf:NaN -+0:+0:0 -+1:+0:1 -+0:+1:-1 -+1:+1:0 --1:+0:-1 -+0:-1:1 --1:-1:0 --1:+1:-2 -+1:-1:2 -+9:+1:8 -+99:+1:98 -+999:+1:998 -+9999:+1:9998 -+99999:+1:99998 -+999999:+1:999998 -+9999999:+1:9999998 -+99999999:+1:99999998 -+999999999:+1:999999998 -+9999999999:+1:9999999998 -+99999999999:+1:99999999998 -+10:-1:11 -+100:-1:101 -+1000:-1:1001 -+10000:-1:10001 -+100000:-1:100001 -+1000000:-1:1000001 -+10000000:-1:10000001 -+100000000:-1:100000001 -+1000000000:-1:1000000001 -+10000000000:-1:10000000001 -+123456789:+987654321:-864197532 --123456789:+987654321:-1111111110 --123456789:-987654321:864197532 -+123456789:-987654321:1111111110 -&bmul -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 -+0:-1:0 --1:+0:0 -123456789123456789:0:0 -0:123456789123456789:0 --1:-1:1 --1:+1:-1 -+1:-1:-1 -+1:+1:1 -+2:+3:6 --2:+3:-6 -+2:-3:-6 --2:-3:6 -111:111:12321 -10101:10101:102030201 -1001001:1001001:1002003002001 -100010001:100010001:10002000300020001 -10000100001:10000100001:100002000030000200001 -11111111111:9:99999999999 -22222222222:9:199999999998 -33333333333:9:299999999997 -44444444444:9:399999999996 -55555555555:9:499999999995 -66666666666:9:599999999994 -77777777777:9:699999999993 -88888888888:9:799999999992 -99999999999:9:899999999991 -+25:+25:625 -+12345:+12345:152399025 -+99999:+11111:1111088889 -9999:10000:99990000 -99999:100000:9999900000 -999999:1000000:999999000000 -9999999:10000000:99999990000000 -99999999:100000000:9999999900000000 -999999999:1000000000:999999999000000000 -9999999999:10000000000:99999999990000000000 -99999999999:100000000000:9999999999900000000000 -999999999999:1000000000000:999999999999000000000000 -9999999999999:10000000000000:99999999999990000000000000 -99999999999999:100000000000000:9999999999999900000000000000 -999999999999999:1000000000000000:999999999999999000000000000000 -9999999999999999:10000000000000000:99999999999999990000000000000000 -99999999999999999:100000000000000000:9999999999999999900000000000000000 -999999999999999999:1000000000000000000:999999999999999999000000000000000000 -9999999999999999999:10000000000000000000:99999999999999999990000000000000000000 -3:3.5:10.5^ -3.5:3:10.5^ -&bdiv-list -100:20:5,0 -4095:4095:1,0 --4095:-4095:1,0 -4095:-4095:-1,0 --4095:4095:-1,0 -123:2:61.5,1 -9:5:1.8,4 -9:4:2.25,1 -# inf handling and general remainder -5:8:0.625,5 -0:8:0,0 -11:2:5.5,1 -11:-2:-5.5,-1 --11:2:-5.5,1 -# see table in documentation in MBI -0:inf:0,0 -0:-inf:0,0 -5:inf:0,5 -5:-inf:0,5 --5:inf:0,-5 --5:-inf:0,-5 -inf:5:inf,0 --inf:5:-inf,0 -inf:-5:-inf,0 --inf:-5:inf,0 -5:5:1,0 --5:-5:1,0 -inf:inf:NaN,NaN --inf:-inf:NaN,NaN --inf:inf:NaN,NaN -inf:-inf:NaN,NaN -8:0:inf,8 -inf:0:inf,inf -# exceptions to reminder rule --8:0:-inf,-8 --inf:0:-inf,-inf -0:0:NaN,NaN -&bdiv -abc:abc:NaN -abc:1:NaN -1:abc:NaN -0:0:NaN -# inf handling (see table in doc) -0:inf:0 -0:-inf:0 -5:inf:0 -5:-inf:0 --5:inf:0 --5:-inf:0 -inf:5:inf --inf:5:-inf -inf:-5:-inf --inf:-5:inf -5:5:1 --5:-5:1 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:inf -inf:0:inf --8:0:-inf --inf:0:-inf -0:0:NaN -11:2:5.5^ --11:-2:5.5^ --11:2:-5.5^ -11:-2:-5.5^ -0:1:0 -0:-1:0 -1:1:1 --1:-1:1 -1:-1:-1 --1:1:-1 -1:2:0.5^ -2:1:2 -1000000000:9:111111111.1111111111111111111111111111111^ -2000000000:9:222222222.2222222222222222222222222222222^ -3000000000:9:333333333.3333333333333333333333333333333^ -4000000000:9:444444444.4444444444444444444444444444444^ -5000000000:9:555555555.5555555555555555555555555555556^ -6000000000:9:666666666.6666666666666666666666666666667^ -7000000000:9:777777777.7777777777777777777777777777778^ -8000000000:9:888888888.8888888888888888888888888888889^ -9000000000:9:1000000000 -35500000:113:314159.2920353982300884955752212389380531^ -71000000:226:314159.2920353982300884955752212389380531^ -106500000:339:314159.2920353982300884955752212389380531^ -1000000000:3:333333333.3333333333333333333333333333333^ -+10:+5:2 -+100:+4:25 -+1000:+8:125 -+10000:+16:625 -999999999999:9:111111111111 -999999999999:99:10101010101 -999999999999:999:1001001001 -999999999999:9999:100010001 -999999999999999:99999:10000100001 -+1111088889:99999:11111 --5:-3:1.666666666666666666666666666666666666667^ --5:3:-1.666666666666666666666666666666666666667^ -4:3:1.333333333333333333333333333333333333333^ -4:-3:-1.333333333333333333333333333333333333333^ -1:3:0.3333333333333333333333333333333333333333^ -1:-3:-0.3333333333333333333333333333333333333333^ --2:-3:0.6666666666666666666666666666666666666667^ --2:3:-0.6666666666666666666666666666666666666667^ -8:5:1.6^ --8:5:-1.6^ -14:-3:-4.666666666666666666666666666666666666667^ --14:3:-4.666666666666666666666666666666666666667^ --14:-3:4.666666666666666666666666666666666666667^ -14:3:4.666666666666666666666666666666666666667^ -# bug in Calc with '99999' vs $BASE-1 -#10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576 -12:24:0.5^ -&bmod -# inf handling, see table in doc -0:inf:0 -0:-inf:0 -5:inf:5 -5:-inf:5 --5:inf:-5 --5:-inf:-5 -inf:5:0 --inf:5:0 -inf:-5:0 --inf:-5:0 -5:5:0 --5:-5:0 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:8 -inf:0:inf -# exceptions to reminder rule --inf:0:-inf --8:0:-8 -0:0:NaN -abc:abc:NaN -abc:1:abc:NaN -1:abc:NaN -0:0:NaN -0:1:0 -1:0:1 -0:-1:0 --1:0:-1 -1:1:0 --1:-1:0 -1:-1:0 --1:1:0 -1:2:1 -2:1:0 -1000000000:9:1 -2000000000:9:2 -3000000000:9:3 -4000000000:9:4 -5000000000:9:5 -6000000000:9:6 -7000000000:9:7 -8000000000:9:8 -9000000000:9:0 -35500000:113:33 -71000000:226:66 -106500000:339:99 -1000000000:3:1 -10:5:0 -100:4:0 -1000:8:0 -10000:16:0 -999999999999:9:0 -999999999999:99:0 -999999999999:999:0 -999999999999:9999:0 -999999999999999:99999:0 --9:+5:1 -+9:-5:-1 --9:-5:-4 --5:3:1 --2:3:1 -4:3:1 -1:3:1 --5:-3:-2 --2:-3:-2 -4:-3:-2 -1:-3:-2 -4095:4095:0 -100041000510123:3:0 -152403346:12345:4321 -9:5:4 -&bgcd -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 -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 -&band -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:0 -3:2:2 -+8:+2:0 -+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 -# equal arguments are treated special, so also do some test with unequal ones -0xFFFF:0xFFFF:0x0xFFFF -0xFFFFFF:0xFFFFFF:0x0xFFFFFF -0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF -0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0x0xF0F0 -0x0F0F:0x0F0F:0x0x0F0F -0xF0F0F0:0xF0F0F0:0x0xF0F0F0 -0x0F0F0F:0x0F0F0F:0x0x0F0F0F -0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 -0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F -0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F -0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F -&bior -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:3 -+8:+2:10 -+281474976710656:0:281474976710656 -+281474976710656:1:281474976710657 -+281474976710656:281474976710656:281474976710656 --2:-3:-1 --1:-1:-1 --6:-6:-6 --7:4:-3 --4:7:-1 -# equal arguments are treated special, so also do some test with unequal ones -0xFFFF:0xFFFF:0x0xFFFF -0xFFFFFF:0xFFFFFF:0x0xFFFFFF -0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF -0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0:0xFFFF:0x0xFFFF -0:0xFFFFFF:0x0xFFFFFF -0:0xFFFFFFFF:0x0xFFFFFFFF -0:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xFFFF:0:0x0xFFFF -0xFFFFFF:0:0x0xFFFFFF -0xFFFFFFFF:0:0x0xFFFFFFFF -0xFFFFFFFFFF:0:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0x0xF0F0 -0x0F0F:0x0F0F:0x0x0F0F -0xF0F0:0x0F0F:0x0xFFFF -0xF0F0F0:0xF0F0F0:0x0xF0F0F0 -0x0F0F0F:0x0F0F0F:0x0x0F0F0F -0x0F0F0F:0xF0F0F0:0x0xFFFFFF -0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 -0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F -0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF -0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F -0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F -0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -&bxor -abc:abc:NaN -abc:0:NaN -0:abc:NaN -1:2:3 -+8:+2:10 -+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 -# equal arguments are treated special, so also do some test with unequal ones -0xFFFF:0xFFFF:0 -0xFFFFFF:0xFFFFFF:0 -0xFFFFFFFF:0xFFFFFFFF:0 -0xFFFFFFFFFF:0xFFFFFFFFFF:0 -0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0 -0:0xFFFF:0x0xFFFF -0:0xFFFFFF:0x0xFFFFFF -0:0xFFFFFFFF:0x0xFFFFFFFF -0:0xFFFFFFFFFF:0x0xFFFFFFFFFF -0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF -0xFFFF:0:0x0xFFFF -0xFFFFFF:0:0x0xFFFFFF -0xFFFFFFFF:0:0x0xFFFFFFFF -0xFFFFFFFFFF:0:0x0xFFFFFFFFFF -0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF -0xF0F0:0xF0F0:0 -0x0F0F:0x0F0F:0 -0xF0F0:0x0F0F:0x0xFFFF -0xF0F0F0:0xF0F0F0:0 -0x0F0F0F:0x0F0F0F:0 -0x0F0F0F:0xF0F0F0:0x0xFFFFFF -0xF0F0F0F0:0xF0F0F0F0:0 -0x0F0F0F0F:0x0F0F0F0F:0 -0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF -0xF0F0F0F0F0:0xF0F0F0F0F0:0 -0x0F0F0F0F0F:0x0F0F0F0F0F:0 -0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF -0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0 -0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0 -0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF -&bnot -abc:NaN -+0:-1 -+8:-9 -+281474976710656:-281474976710657 --1:0 --2:1 --12:11 -&digit -0:0:0 -12:0:2 -12:1:1 -123:0:3 -123:1:2 -123:2:1 -123:-1:1 -123:-2:2 -123:-3:3 -123456:0:6 -123456:1:5 -123456:2:4 -123456:3:3 -123456:4:2 -123456:5:1 -123456:-1:1 -123456:-2:2 -123456:-3:3 -100000:-3:0 -100000:0:0 -100000:1:0 -&mantissa -abc:NaN -1e4:1 -2e0:2 -123:123 --1:-1 --2:-2 -+inf:inf --inf:-inf -&exponent -abc:NaN -1e4:4 -2e0:0 -123:0 --1:0 --2:0 -0:1 -+inf:inf --inf:inf -&parts -abc:NaN,NaN -1e4:1,4 -2e0:2,0 -123:123,0 --1:-1,0 --2:-2,0 -0:0,1 -+inf:inf,inf --inf:-inf,inf -&bfac --1:NaN -NaNfac:NaN -+inf:inf --inf:NaN -0:1 -1:1 -2:2 -3:6 -4:24 -5:120 -6:720 -10:3628800 -11:39916800 -12:479001600 -&bpow -abc:12:NaN -12:abc:NaN -0:0:1 -0:1:0 -0:2:0 -0:-1:inf -0:-2:inf -1:0:1 -1:1:1 -1:2:1 -1:3:1 -1:-1:1 -1:-2:1 -1:-3:1 -2:0:1 -2:1:2 -2:2:4 -2:3:8 -3:3:27 -2:-1:0.5^ --2:-1:-0.5^ -2:-2:0.25^ -# Y is even => result positive --2:-2:0.25^ -# Y is odd => result negative --2:-3:-0.125^ -+inf:1234500012:inf --inf:1234500012:inf --inf:1234500013:-inf -+inf:-12345000123:inf --inf:-12345000123:-inf -# 1 ** -x => 1 / (1 ** x) --1:0:1 --2:0:1 --1:1:-1 --1:2:1 --1:3:-1 --1:4:1 --1:5:-1 --1:-1:-1 --1:-2:1 --1:-3:-1 --1:-4:1 --2:2:4 --2:3:-8 --2:4:16 --2:5:-32 --3:2:9 --3:3:-27 --3:4:81 --3:5:-243 -10:2:100 -10:3:1000 -10:4:10000 -10:5:100000 -10:6:1000000 -10:7:10000000 -10:8:100000000 -10:9:1000000000 -10:20:100000000000000000000 -123456:2:15241383936 -#2:0.5:1.41^ -&length -100:3 -10:2 -1:1 -0:1 -12345:5 -10000000000000000:17 --123:3 -215960156869840440586892398248:30 -# broot always upgrades -&broot -144:2:12^ -123:2:11.09053650640941716205160010260993291846^ -# bsqrt always upgrades -&bsqrt -145:12.04159457879229548012824103037860805243^ -144:12^ -143:11.95826074310139802112984075619561661399^ -16:4 -170:13.03840481040529742916594311485836883306^ -169:13 -168:12.96148139681572046193193487217599331541^ -4:2 -3:1.732050807568877293527446341505872366943^ -2:1.41421356237309504880168872420969807857^ -9:3 -12:3.464101615137754587054892683011744733886^ -256:16 -100000000:10000 -4000000000000:2000000 -152399026:12345.00004050222755607815159966235881398^ -152399025:12345 -152399024:12344.99995949777231103967404745303741942^ -1:1 -0:0 --2:NaN --123:NaN -Nan:NaN -+inf:inf --inf: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 -123456:5:123450 -123456:6:123456 -+10123456789:5:10123000000 --10123456789:5:-10123000000 -+10123456789:9:10123456700 --10123456789:9:-10123456700 -+101234500:6:101234000 --101234500:6:-101234000 -#+101234500:-4:101234000 -#-101234500:-4:-101234000 -$round_mode('zero') -+20123456789:5:20123000000 --20123456789:5:-20123000000 -+20123456789:9:20123456800 --20123456789:9:-20123456800 -+201234500:6:201234000 --201234500:6:-201234000 -#+201234500:-4:201234000 -#-201234500:-4:-201234000 -+12345000:4:12340000 --12345000:4:-12340000 -$round_mode('+inf') -+30123456789:5:30123000000 --30123456789:5:-30123000000 -+30123456789:9:30123456800 --30123456789:9:-30123456800 -+301234500:6:301235000 --301234500:6:-301234000 -#+301234500:-4:301235000 -#-301234500:-4:-301234000 -+12345000:4:12350000 --12345000:4:-12340000 -$round_mode('-inf') -+40123456789:5:40123000000 --40123456789:5:-40123000000 -+40123456789:9:40123456800 --40123456789:9:-40123456800 -+401234500:6:401234000 -+401234500:6:401234000 -#-401234500:-4:-401235000 -#-401234500:-4:-401235000 -+12345000:4:12340000 --12345000:4:-12350000 -$round_mode('odd') -+50123456789:5:50123000000 --50123456789:5:-50123000000 -+50123456789:9:50123456800 --50123456789:9:-50123456800 -+501234500:6:501235000 --501234500:6:-501235000 -#+501234500:-4:501235000 -#-501234500:-4:-501235000 -+12345000:4:12350000 --12345000:4:-12350000 -$round_mode('even') -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601234000 --601234500:6:-601234000 -#+601234500:-4:601234000 -#-601234500:-4:-601234000 -#-601234500:-9:0 -#-501234500:-9:0 -#-601234500:-8:0 -#-501234500:-8:0 -+1234567:7:1234567 -+1234567:6:1234570 -+12345000:4:12340000 --12345000:4:-12340000 -&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 --2: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 -2:2 -3:3 -abc:NaN -&as_hex -128:0x80 --128:-0x80 -0:0x0 --0:0x0 -1:0x1 -0x123456789123456789:0x123456789123456789 -+inf:inf --inf:-inf -NaNas_hex:NaN -&as_bin -128:0b10000000 --128:-0b10000000 -0:0b0 --0:0b0 -1:0b1 -0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101 -+inf:inf --inf:-inf -NaNas_bin:NaN diff --git a/lib/Math/BigInt/t/upgrade.t b/lib/Math/BigInt/t/upgrade.t deleted file mode 100644 index 20d8990c55..0000000000 --- a/lib/Math/BigInt/t/upgrade.t +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/upgrade.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 2112 - + 2; # our own tests - } - -use Math::BigInt upgrade => 'Math::BigFloat'; -use Math::BigFloat; - -use vars qw ($scale $class $try $x $y $f @args $ans $ans1 $ans1_str $setup - $ECL $CL); -$class = "Math::BigInt"; -$CL = "Math::BigInt::Calc"; -$ECL = "Math::BigFloat"; - -ok (Math::BigInt->upgrade(),'Math::BigFloat'); -ok (Math::BigInt->downgrade()||'',''); - -require 'upgrade.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/upgradef.t b/lib/Math/BigInt/t/upgradef.t deleted file mode 100644 index 437268db65..0000000000 --- a/lib/Math/BigInt/t/upgradef.t +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/perl -w - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/upgradef.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 0 - + 6; # our own tests - } - -############################################################################### -package Math::BigFloat::Test; - -use Math::BigFloat; -require Exporter; -use vars qw/@ISA/; -@ISA = qw/Exporter Math::BigFloat/; - -use overload; - -sub isa - { - my ($self,$class) = @_; - return if $class =~ /^Math::Big(Int|Float)/; # we aren't one of these - UNIVERSAL::isa($self,$class); - } - -sub bmul - { - return __PACKAGE__->new(123); - } - -sub badd - { - return __PACKAGE__->new(321); - } - -############################################################################### -package main; - -# use Math::BigInt upgrade => 'Math::BigFloat'; -use Math::BigFloat upgrade => 'Math::BigFloat::Test'; - -use vars qw ($scale $class $try $x $y $z $f @args $ans $ans1 $ans1_str $setup - $ECL $CL); -$class = "Math::BigFloat"; -$CL = "Math::BigInt::Calc"; -$ECL = "Math::BigFloat::Test"; - -ok (Math::BigFloat->upgrade(),$ECL); -ok (Math::BigFloat->downgrade()||'',''); - -$x = $class->new(123); $y = $ECL->new(123); $z = $x->bmul($y); -ok (ref($z),$ECL); ok ($z,123); - -$x = $class->new(123); $y = $ECL->new(123); $z = $x->badd($y); -ok (ref($z),$ECL); ok ($z,321); - - - -# not yet: -# require 'upgrade.inc'; # all tests here for sharing diff --git a/lib/Math/BigInt/t/use.t b/lib/Math/BigInt/t/use.t deleted file mode 100644 index 1f09f5e43c..0000000000 --- a/lib/Math/BigInt/t/use.t +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/perl -w - -# use Module(); doesn't call import() - thanx for cpan testers David. M. Town -# and Andreas Marcel Riechert for spotting it. It is fixed by the same code -# that fixes require Math::BigInt, but we make a test to be sure it really -# works. - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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 => 1; - } - -my ($try,$ans,$x); - -use Math::BigInt(); $x = Math::BigInt->new(1); ++$x; - -ok ($x||'undef',2); - -# all tests done - -1; - diff --git a/lib/Math/BigInt/t/use_lib1.t b/lib/Math/BigInt/t/use_lib1.t deleted file mode 100644 index a6eda82b37..0000000000 --- a/lib/Math/BigInt/t/use_lib1.t +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/perl -w - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use_lib1.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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; - } - -use Math::BigFloat lib => 'BareCalc'; - -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); - diff --git a/lib/Math/BigInt/t/use_lib2.t b/lib/Math/BigInt/t/use_lib2.t deleted file mode 100644 index aa4ba5fbe2..0000000000 --- a/lib/Math/BigInt/t/use_lib2.t +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/perl -w - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use_lib2.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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; - } - -use Math::BigInt; -use Math::BigFloat lib => 'BareCalc'; - -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); - diff --git a/lib/Math/BigInt/t/use_lib3.t b/lib/Math/BigInt/t/use_lib3.t deleted file mode 100644 index b46b939551..0000000000 --- a/lib/Math/BigInt/t/use_lib3.t +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/perl -w - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use_lib3.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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; - } - -use Math::BigInt lib => 'BareCalc'; -use Math::BigFloat; - -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); - diff --git a/lib/Math/BigInt/t/use_lib4.t b/lib/Math/BigInt/t/use_lib4.t deleted file mode 100644 index bfd85d5f70..0000000000 --- a/lib/Math/BigInt/t/use_lib4.t +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl -w - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent, except this, since the later overrides -# the former lib statement - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use_lib4.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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; - } - -use Math::BigInt lib => 'BareCalc'; -use Math::BigFloat lib => 'Calc'; - -ok (Math::BigInt->config()->{lib},'Math::BigInt::Calc'); - -ok (Math::BigFloat->new(123)->badd(123),246); - diff --git a/lib/Math/BigInt/t/use_mbfw.t b/lib/Math/BigInt/t/use_mbfw.t deleted file mode 100644 index c6a047143e..0000000000 --- a/lib/Math/BigInt/t/use_mbfw.t +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl -w - -# check that using BigFloat with "with" and "lib" at the same time works -# broken in versions up to v1.63 - -use strict; -use Test; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/use_mbfw.t//i; - if ($ENV{PERL_CORE}) - { - # testing with the core distribution - @INC = qw(../t/lib); - } - unshift @INC, qw(../lib); # to locate the modules - 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; - } - - -# the replacement lib can handle the lib statement, but it could also ignore -# it completely, for instance, when it is a 100% replacement for BigInt, but -# doesn't know the concept of alternative libs. But it still needs to cope -# with "lib => ". SubClass does record it, so we test here essential if -# BigFloat hands the lib properly down, any more is outside out testing reach. - -use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'BareCalc'; - -ok (Math::BigFloat->config()->{with}, 'Math::BigInt::BareCalc' ); - -# ok ($Math::BigInt::Subclass::lib, 'BareCalc' ); - -# it never arrives here, but that is a design decision in SubClass -ok (Math::BigInt->config->{lib}, 'Math::BigInt::BareCalc' ); - -# all tests done - diff --git a/lib/Math/BigInt/t/with_sub.t b/lib/Math/BigInt/t/with_sub.t deleted file mode 100644 index 878fe07f1f..0000000000 --- a/lib/Math/BigInt/t/with_sub.t +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl -w - -# Test use Math::BigFloat with => 'Math::BigInt::SomeSubclass'; - -use Test; -use strict; - -BEGIN - { - $| = 1; - # to locate the testing files - my $location = $0; $location =~ s/with_sub.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 => 2308 - + 1; - } - -use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'Calc'; - -use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); -$class = "Math::BigFloat"; -$CL = "Math::BigInt::Calc"; - -# the with argument is ignored -ok (Math::BigFloat->config()->{with}, 'Math::BigInt::Calc'); - -require 'bigfltpm.inc'; # all tests here for sharing |