From 17066fb7b8852ea22230dc9b174de2d10bf34f3f Mon Sep 17 00:00:00 2001 From: James E Keenan Date: Thu, 2 Nov 2023 16:59:22 -0400 Subject: [PATCH] cpan/Math-BigInt - Update to version 2.000000 (All library and test updates by Peter John Acklam.) 2.000000 2023-10-29 * Merge the Math-BigRat distribution into the Math-BigInt distribution. This merge eliminates the problems that users have experienced when incompatible versions of the two distributions have been installed. This fixes CPAN RT #143228. * Add method from_dec() to Math::BigRat to make Math::BigRat more consistent with Math::BigInt and Math::BigFloat. * To be consistent with Math::BigInt and Math::BigFloat, make it possible to use "require" with Math::BigRat, e.g., require Math::BigRat; $x = Math::BigRat -> bone(); * Fix cases where "require" doesn't work for Math::BigInt and Math::BigFloat, and add tests to verify that "require" works for Math::BigInt, Math::BigRat, and Math::BigFloat. * Add methods bblsft() and bbrsft() to Math::BigRat to make Math::BigRat consistent with Math::BigInt and Math::BigFloat. These methods do bitwise left and right shift, respectively. * Fix bug in to_oct() and to_bin() in Math::BigFloat. They called to_hex() when upgrading, but should have called to_oct() and to_bin(), respectively. * Add to_hex(), to_oct(), to_bin() to Math::BigRat. * Add new method binv() to Math::BigInt, Math::BigFloat, and Math::BigRat. * Improve as_float() and as_rat(). * POD updates. Committer: As part of synching Math-BigInt-2.000000 into blead, the Math-BigRat distribution was removed from Porting/Maintainers.pl, MANIFEST, etc. --- MANIFEST | 49 +- Porting/Maintainers.pl | 17 +- cpan/Math-BigInt/lib/Math/BigFloat.pm | 209 +- cpan/Math-BigInt/lib/Math/BigInt.pm | 280 ++- cpan/Math-BigInt/lib/Math/BigInt/Calc.pm | 2 +- cpan/Math-BigInt/lib/Math/BigInt/Lib.pm | 2 +- .../lib/Math/BigRat.pm | 333 +++- .../t/Math/BigRat/Test.pm | 0 cpan/{Math-BigRat => Math-BigInt}/t/big_ap.t | 0 .../{Math-BigRat => Math-BigInt}/t/bigfltrt.t | 0 cpan/{Math-BigRat => Math-BigInt}/t/bigrat.t | 0 .../t/bigratpm.inc | 0 .../{Math-BigRat => Math-BigInt}/t/bigratpm.t | 0 .../{Math-BigRat => Math-BigInt}/t/bigratup.t | 0 .../bitwise.t => Math-BigInt/t/bitwise-mbr.t} | 0 .../t/{downgrade.t => downgrade-mbi-mbf.t} | 0 .../t/downgrade-mbi-mbr.t} | 0 .../t/hang.t => Math-BigInt/t/hang-mbr.t} | 0 cpan/Math-BigInt/t/req_mbf0.t | 15 - cpan/Math-BigInt/t/req_mbf1.t | 15 - cpan/Math-BigInt/t/req_mbfa.t | 15 - cpan/Math-BigInt/t/req_mbfi.t | 15 - cpan/Math-BigInt/t/req_mbfn.t | 16 - cpan/Math-BigInt/t/req_mbfw.t | 29 - cpan/Math-BigInt/t/require.t | 17 - .../{Math-BigRat => Math-BigInt}/t/rt121139.t | 0 cpan/Math-BigInt/t/trap.t | 122 +- cpan/Math-BigInt/t/upgrade2.t | 55 +- cpan/Math-BigInt/t/use_lib1.t | 18 - cpan/Math-BigInt/t/use_lib2.t | 19 - cpan/Math-BigInt/t/use_lib3.t | 19 - cpan/Math-BigInt/t/use_lib4.t | 20 - cpan/Math-BigInt/t/use_lib5.t | 19 - cpan/Math-BigInt/t/use_lib6.t | 16 - cpan/Math-BigRat/t/badd-mbr.t | 164 -- cpan/Math-BigRat/t/bigfltpm.inc | 1673 ----------------- cpan/Math-BigRat/t/binv-mbr.t | 89 - cpan/Math-BigRat/t/bnok-mbr.t | 1451 -------------- cpan/Math-BigRat/t/const-mbr.t | 319 ---- cpan/Math-BigRat/t/dparts-mbr.t | 67 - cpan/Math-BigRat/t/fparts-mbr.t | 97 - cpan/Math-BigRat/t/new-mbr.t | 68 - cpan/Math-BigRat/t/requirer.t | 18 - cpan/Math-BigRat/t/trap.t | 105 -- t/porting/known_pod_issues.dat | 2 +- 45 files changed, 825 insertions(+), 4530 deletions(-) rename cpan/{Math-BigRat => Math-BigInt}/lib/Math/BigRat.pm (91%) rename cpan/{Math-BigRat => Math-BigInt}/t/Math/BigRat/Test.pm (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/big_ap.t (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/bigfltrt.t (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/bigrat.t (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/bigratpm.inc (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/bigratpm.t (100%) rename cpan/{Math-BigRat => Math-BigInt}/t/bigratup.t (100%) rename cpan/{Math-BigRat/t/bitwise.t => Math-BigInt/t/bitwise-mbr.t} (100%) rename cpan/Math-BigInt/t/{downgrade.t => downgrade-mbi-mbf.t} (100%) rename cpan/{Math-BigRat/t/downgrade.t => Math-BigInt/t/downgrade-mbi-mbr.t} (100%) rename cpan/{Math-BigRat/t/hang.t => Math-BigInt/t/hang-mbr.t} (100%) delete mode 100644 cpan/Math-BigInt/t/req_mbf0.t delete mode 100644 cpan/Math-BigInt/t/req_mbf1.t delete mode 100644 cpan/Math-BigInt/t/req_mbfa.t delete mode 100644 cpan/Math-BigInt/t/req_mbfi.t delete mode 100644 cpan/Math-BigInt/t/req_mbfn.t delete mode 100644 cpan/Math-BigInt/t/req_mbfw.t delete mode 100644 cpan/Math-BigInt/t/require.t rename cpan/{Math-BigRat => Math-BigInt}/t/rt121139.t (100%) delete mode 100644 cpan/Math-BigInt/t/use_lib1.t delete mode 100644 cpan/Math-BigInt/t/use_lib2.t delete mode 100644 cpan/Math-BigInt/t/use_lib3.t delete mode 100644 cpan/Math-BigInt/t/use_lib4.t delete mode 100644 cpan/Math-BigInt/t/use_lib5.t delete mode 100644 cpan/Math-BigInt/t/use_lib6.t delete mode 100644 cpan/Math-BigRat/t/badd-mbr.t delete mode 100644 cpan/Math-BigRat/t/bigfltpm.inc delete mode 100644 cpan/Math-BigRat/t/binv-mbr.t delete mode 100644 cpan/Math-BigRat/t/bnok-mbr.t delete mode 100644 cpan/Math-BigRat/t/const-mbr.t delete mode 100644 cpan/Math-BigRat/t/dparts-mbr.t delete mode 100644 cpan/Math-BigRat/t/fparts-mbr.t delete mode 100644 cpan/Math-BigRat/t/new-mbr.t delete mode 100644 cpan/Math-BigRat/t/requirer.t delete mode 100644 cpan/Math-BigRat/t/trap.t diff --git a/MANIFEST b/MANIFEST index d04ce3514add..7f1da1af40f8 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1571,28 +1571,38 @@ cpan/Math-BigInt/lib/Math/BigFloat.pm An arbitrary precision floating-point ar cpan/Math-BigInt/lib/Math/BigInt.pm An arbitrary precision integer arithmetic package cpan/Math-BigInt/lib/Math/BigInt/Calc.pm Pure Perl module to support Math::BigInt cpan/Math-BigInt/lib/Math/BigInt/Lib.pm Module related to Math::BigInt +cpan/Math-BigInt/lib/Math/BigRat.pm Math-BigInt cpan/Math-BigInt/t/alias.inc Support for BigInt tests cpan/Math-BigInt/t/bare_mbf.t Test MBF under Math::BigInt::BareCalc cpan/Math-BigInt/t/bare_mbi.t Test MBI under Math::BigInt::BareCalc cpan/Math-BigInt/t/bare_mif.t Rounding tests under BareCalc cpan/Math-BigInt/t/bfround_numify.t Test file related to Math::BigInt +cpan/Math-BigInt/t/big_ap.t Math-BigInt cpan/Math-BigInt/t/big_pi_e.t test bpi() and bexp() cpan/Math-BigInt/t/bigfltpm.inc Shared tests for bigfltpm.t and sub_mbf.t cpan/Math-BigInt/t/bigfltpm.t See if BigFloat.pm works +cpan/Math-BigInt/t/bigfltrt.t Math-BigInt cpan/Math-BigInt/t/bigintc.t See if BigInt/Calc.pm works cpan/Math-BigInt/t/bigintc-import.t Test file related to Math::BigInt cpan/Math-BigInt/t/bigintpm.inc Shared tests for bigintpm.t and sub_mbi.t cpan/Math-BigInt/t/bigintpm.t See if BigInt.pm works cpan/Math-BigInt/t/bigints.t See if BigInt.pm works cpan/Math-BigInt/t/biglog.t Test the log function +cpan/Math-BigInt/t/bigrat.t Math-BigInt +cpan/Math-BigInt/t/bigratpm.inc Math-BigInt +cpan/Math-BigInt/t/bigratpm.t Math-BigInt +cpan/Math-BigInt/t/bigratup.t Math-BigInt cpan/Math-BigInt/t/bigroot.t Test the broot function +cpan/Math-BigInt/t/bitwise-mbr.t Math-BigInt cpan/Math-BigInt/t/calling-class-methods.t Test Math::BigInt cpan/Math-BigInt/t/calling-constant.t Test file related to Math::BigInt cpan/Math-BigInt/t/calling-instance-methods.t Test Math::BigInt cpan/Math-BigInt/t/calling-lib1.t Test file related to Math::BigInt cpan/Math-BigInt/t/calling-lib2.t Test file related to Math::BigInt cpan/Math-BigInt/t/config.t Test Math::BigInt->config() -cpan/Math-BigInt/t/downgrade.t Test if use Math::BigInt(); under downgrade works +cpan/Math-BigInt/t/downgrade-mbi-mbf.t Math-BigInt +cpan/Math-BigInt/t/downgrade-mbi-mbr.t Math-BigInt +cpan/Math-BigInt/t/hang-mbr.t Math-BigInt cpan/Math-BigInt/t/inf_nan.t Special tests for inf and *NaN* handling cpan/Math-BigInt/t/isa.t Test for Math::BigInt inheritance cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm Math-BigInt @@ -1602,6 +1612,7 @@ cpan/Math-BigInt/t/Math/BigInt/Lib/Minimal.pm Module related to Math::BigInt cpan/Math-BigInt/t/Math/BigInt/Lib/TestUtil.pm Test Math::BigInt cpan/Math-BigInt/t/Math/BigInt/Scalar.pm Pure Perl module to support Math::BigInt cpan/Math-BigInt/t/Math/BigInt/Subclass.pm Empty subclass of BigInt for test +cpan/Math-BigInt/t/Math/BigRat/Test.pm Math-BigInt cpan/Math-BigInt/t/mbf_ali.t Tests for BigFloat cpan/Math-BigInt/t/mbi_ali.t Tests for BigInt cpan/Math-BigInt/t/mbi_rand.t Test Math::BigInt randomly @@ -1609,15 +1620,9 @@ cpan/Math-BigInt/t/mbimbf.inc Actual BigInt/BigFloat accuracy, precision and cpan/Math-BigInt/t/mbimbf.t BigInt/BigFloat accuracy, precision and fallback, round_mode cpan/Math-BigInt/t/nan_cmp.t overloaded comparison involving *NaN* cpan/Math-BigInt/t/new_overloaded.t test overloaded numbers in BigFloat's new() -cpan/Math-BigInt/t/req_mbf0.t test: require Math::BigFloat; ->bzero(); -cpan/Math-BigInt/t/req_mbf1.t test: require Math::BigFloat; ->bone(); -cpan/Math-BigInt/t/req_mbfa.t test: require Math::BigFloat; ->bnan(); -cpan/Math-BigInt/t/req_mbfi.t test: require Math::BigFloat; ->binf(); -cpan/Math-BigInt/t/req_mbfn.t test: require Math::BigFloat; ->new(); -cpan/Math-BigInt/t/req_mbfw.t require Math::BigFloat; import ( with => ); -cpan/Math-BigInt/t/require.t Test if require Math::BigInt works cpan/Math-BigInt/t/round.t Test rounding with non-integer A and P cpan/Math-BigInt/t/rt-16221.t Tests for objectify() w/foreign objs +cpan/Math-BigInt/t/rt121139.t Math-BigInt cpan/Math-BigInt/t/sub_ali.t Tests for aliases in BigInt subclasses cpan/Math-BigInt/t/sub_mbf.t Empty subclass test of BigFloat cpan/Math-BigInt/t/sub_mbi.t Empty subclass test of BigInt @@ -1628,12 +1633,6 @@ cpan/Math-BigInt/t/upgrade.t Test if use Math::BigInt(); under upgrade works cpan/Math-BigInt/t/upgrade2.t Test that two upgrade levels work cpan/Math-BigInt/t/upgradef.t Test if use Math::BigFloat(); under upgrade works cpan/Math-BigInt/t/use.t Test if use Math::BigInt(); works -cpan/Math-BigInt/t/use_lib1.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib2.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib3.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib4.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib5.t Test file related to Math::BigInt -cpan/Math-BigInt/t/use_lib6.t Test file related to Math::BigInt cpan/Math-BigInt/t/use_mbfw.t use BigFloat w/ with and lib at the same time cpan/Math-BigInt/t/with_sub.t Test use Math::BigFloat with => package cpan/Math-BigInt-FastCalc/FastCalc.xs Math::BigInt::FastCalc extension @@ -1644,28 +1643,6 @@ cpan/Math-BigInt-FastCalc/t/bigroot.t Test file related to Math::BigInt::FastC cpan/Math-BigInt-FastCalc/t/bootstrap.t Math::BigInt::FastCalc extension cpan/Math-BigInt-FastCalc/t/leak.t test for memory leaks in Math::BigInt::FastCalc cpan/Math-BigInt-FastCalc/t/mbi_rand.t Math::BigInt::FastCalc extension -cpan/Math-BigRat/lib/Math/BigRat.pm Math::BigRat -cpan/Math-BigRat/t/badd-mbr.t -cpan/Math-BigRat/t/big_ap.t Math::BigRat test -cpan/Math-BigRat/t/bigfltpm.inc Math::BigRat test -cpan/Math-BigRat/t/bigfltrt.t Math::BigRat test -cpan/Math-BigRat/t/bigrat.t Math::BigRat test -cpan/Math-BigRat/t/bigratpm.inc Math::BigRat test -cpan/Math-BigRat/t/bigratpm.t Math::BigRat test -cpan/Math-BigRat/t/bigratup.t test under $Math::BigInt::upgrade -cpan/Math-BigRat/t/binv-mbr.t -cpan/Math-BigRat/t/bitwise.t Math::BigRat test -cpan/Math-BigRat/t/bnok-mbr.t -cpan/Math-BigRat/t/const-mbr.t -cpan/Math-BigRat/t/downgrade.t -cpan/Math-BigRat/t/dparts-mbr.t -cpan/Math-BigRat/t/fparts-mbr.t -cpan/Math-BigRat/t/hang.t Math::BigRat test for bug #34584 - hang in exp() -cpan/Math-BigRat/t/Math/BigRat/Test.pm Math::BigRat test helper -cpan/Math-BigRat/t/new-mbr.t -cpan/Math-BigRat/t/requirer.t see if require works properly -cpan/Math-BigRat/t/rt121139.t -cpan/Math-BigRat/t/trap.t see if trap_nan and trap_inf work cpan/Memoize/Memoize.pm Memoize cpan/Memoize/Memoize/AnyDBM_File.pm Memoize glue layer for AnyDBM_File cpan/Memoize/Memoize/Expire.pm Memoize expiry manager example diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index c71e9c93dde8..cc50e3490465 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -757,7 +757,8 @@ package Maintainers; }, 'Math::BigInt' => { - 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-1.999842.tar.gz', + 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-2.000000.tar.gz', + 'SYNCINFO' => 'jkeenan on Thu Nov 2 17:12:13 2023', 'SYNCINFO' => 'jkeenan on Thu Sep 28 07:49:05 2023', 'SYNCINFO' => 'jkeenan on Sun Sep 24 08:09:46 2023', 'FILES' => q[cpan/Math-BigInt], @@ -794,20 +795,6 @@ package Maintainers; ], }, - 'Math::BigRat' => { - 'DISTRIBUTION' => 'PJACKLAM/Math-BigRat-0.2624.tar.gz', - 'FILES' => q[cpan/Math-BigRat], - 'EXCLUDED' => [ - qr{^xt/}, - qr{^math-bigrat-pod.diff}, - qr{^t/author-}, - qr{^t/release-}, - qw( t/00sig.t - t/01load.t - ), - ], - }, - 'Math::Complex' => { 'DISTRIBUTION' => 'ZEFRAM/Math-Complex-1.59.tar.gz', 'FILES' => q[dist/Math-Complex], diff --git a/cpan/Math-BigInt/lib/Math/BigFloat.pm b/cpan/Math-BigInt/lib/Math/BigFloat.pm index fd9aa7d7df69..272b00202bbf 100644 --- a/cpan/Math-BigInt/lib/Math/BigFloat.pm +++ b/cpan/Math-BigInt/lib/Math/BigFloat.pm @@ -20,7 +20,7 @@ use Carp qw< carp croak >; use Scalar::Util qw< blessed >; use Math::BigInt qw< >; -our $VERSION = '1.999842'; +our $VERSION = '2.000000'; $VERSION =~ tr/_//d; require Exporter; @@ -227,7 +227,9 @@ $_trap_inf = 0; # constant for easier life my $nan = 'NaN'; -my $IMPORT = 0; # was import() called yet? used to make require work +# Has import() been called yet? This variable is needed to make "require" work. + +my $IMPORT = 0; # some digits of accuracy for blog(undef, 10); which we use in blog() for speed my $LOG_10 = @@ -318,6 +320,10 @@ sub AUTOLOAD { sub _method_hand_up { exists $hand_ups{$_[0]||''}; } } +# Compare the following function with @ISA above. This inheritance mess needs a +# clean up. When doing so, also consider the BEGIN block and the AUTOLOAD code. +# Fixme! + sub isa { my ($self, $class) = @_; return if $class =~ /^Math::BigInt/; # we aren't one of these @@ -545,6 +551,10 @@ sub from_dec { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_dec'); @@ -575,6 +585,10 @@ sub from_hex { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_hex'); @@ -605,6 +619,10 @@ sub from_oct { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_oct'); @@ -635,6 +653,10 @@ sub from_bin { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bin'); @@ -665,6 +687,10 @@ sub from_ieee754 { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_ieee754'); @@ -839,7 +865,9 @@ sub bzero { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -897,7 +925,9 @@ sub bone { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -970,7 +1000,9 @@ sub binf { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1043,7 +1075,9 @@ sub bnan { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1119,6 +1153,10 @@ sub bpi { my $class = $selfref || $self; my @r = @_; # rounding paramters + # Make "require" work. + + $class -> import() if $IMPORT == 0; + if ($selfref) { # bpi() called as an instance method return $self if $self -> modify('bpi'); } else { # bpi() called as a class method @@ -1329,7 +1367,7 @@ sub as_float { Math::BigFloat -> upgrade(undef); Math::BigFloat -> downgrade(undef); - my $y = Math::BigFloat -> new($x); + my $y = Math::BigFloat -> copy($x); # reset upgrading and downgrading @@ -1339,6 +1377,41 @@ sub as_float { return $y; } +sub as_rat { + # return copy as a Math::BigRat representation of this Math::BigFloat + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + return $x -> copy() if $x -> isa("Math::BigRat"); + + # disable upgrading and downgrading + + require Math::BigRat; + my $upg = Math::BigRat -> upgrade(); + my $dng = Math::BigRat -> downgrade(); + Math::BigRat -> upgrade(undef); + Math::BigRat -> downgrade(undef); + + my $y; + if ($x -> is_inf()) { + $y = Math::BigRat -> binf($x -> sign()); + } elsif ($x -> is_nan()) { + $y = Math::BigRat -> bnan(); + } else { + my @flt_parts = ($x->{sign}, $x->{_m}, $x->{_es}, $x->{_e}); + my @rat_parts = $class -> _flt_lib_parts_to_rat_lib_parts(@flt_parts); + $y = Math::BigRat -> new($rat_parts[0] . $LIB -> _str($rat_parts[1]) + . '/' . $LIB -> _str($rat_parts[2])); + } + + # reset upgrading and downgrading + + Math::BigRat -> upgrade($upg); + Math::BigRat -> downgrade($dng); + + return $y; +} + ############################################################################### # Boolean methods ############################################################################### @@ -2467,6 +2540,23 @@ sub bpow { return $x; } +sub binv { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x->modify('binv'); + + my $inv = $class -> bdiv($class -> bone(), $x, @r); + + return $downgrade -> new($inv, @r) if defined($downgrade) + && ($inv -> is_int() || $inv -> is_inf() || $inv -> is_nan()); + + for my $key (qw/ sign _m _es _e /) { + $x -> {$key} = $inv -> {$key}; + } + + $x; +} + sub blog { # Return the logarithm of the operand. If a second operand is defined, that # value is used as the base, otherwise the base is assumed to be Euler's @@ -3832,64 +3922,80 @@ sub brsft { # Bitwise left shift. sub bblsft { - my ($class, $x, $y, @r) = ref($_[0]) && ref($_[0]) eq ref($_[1]) - ? (ref($_[0]), @_) - : objectify(2, @_); + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; my $xint = Math::BigInt -> bblsft($x, $y, @r); - # disable downgrading + # Temporarily disable downgrading. my $dng = $class -> downgrade(); $class -> downgrade(undef); - # convert to Math::BigFloat without downgrading + # convert to our class without downgrading. my $xflt = $class -> new($xint); - # reset downgrading + # Reset downgrading. $class -> downgrade($dng); - $x -> {sign} = $xflt -> {sign}; - $x -> {_m} = $xflt -> {_m}; - $x -> {_es} = $xflt -> {_es}; - $x -> {_e} = $xflt -> {_e}; + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; + } else { + $x = $xflt; + } - # now we might downgrade + # Now we might downgrade. return $downgrade -> new($x) if defined($downgrade); $x -> round(@r); } -# Bitwise left shift. +# Bitwise right shift. sub bbrsft { - my ($class, $x, $y, @r) = ref($_[0]) && ref($_[0]) eq ref($_[1]) - ? (ref($_[0]), @_) - : objectify(2, @_); + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; my $xint = Math::BigInt -> bbrsft($x, $y, @r); - # disable downgrading + # Temporarily disable downgrading. my $dng = $class -> downgrade(); $class -> downgrade(undef); - # convert to Math::BigFloat without downgrading + # Convert to our class without downgrading. my $xflt = $class -> new($xint); - # reset downgrading + # Reset downgrading. $class -> downgrade($dng); - $x -> {sign} = $xflt -> {sign}; - $x -> {_m} = $xflt -> {_m}; - $x -> {_es} = $xflt -> {_es}; - $x -> {_e} = $xflt -> {_e}; + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; + } else { + $x = $xflt; + } - # now we might downgrade + # Now we might downgrade. return $downgrade -> new($x) if defined($downgrade); $x -> round(@r); @@ -5006,7 +5112,7 @@ sub to_oct { # Upgrade? - return $upgrade -> to_hex($x, @r) + return $upgrade -> to_oct($x, @r) if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -5038,7 +5144,7 @@ sub to_bin { # Upgrade? - return $upgrade -> to_hex($x, @r) + return $upgrade -> to_bin($x, @r) if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -6332,6 +6438,12 @@ Multiply $x by $y, and then add $z to the result. This method was added in v1.87 of Math::BigInt (June 2007). +=item binv() + + $x->binv(); + +Invert the value of $x, i.e., compute 1/$x. + =item bdiv() $q = $x->bdiv($y); @@ -6660,16 +6772,6 @@ See the respective low-level library documentation for further details. See L for more details about using a different low-level library. -=head2 Using Math::BigInt::Lite - -For backwards compatibility reasons it is still possible to -request a different storage class for use with Math::BigFloat: - - use Math::BigFloat with => 'Math::BigInt::Lite'; - -However, this request is ignored, as the current code now uses the low-level -math library for directly storing the number parts. - =head1 EXPORTS C exports nothing by default, but can export the C @@ -6679,21 +6781,6 @@ method: print bpi(10), "\n"; -=head1 CAVEATS - -Do not try to be clever to insert some operations in between switching -libraries: - - require Math::BigFloat; - my $matter = Math::BigFloat->bone() + 4; # load BigInt and Calc - Math::BigFloat->import( lib => 'Pari' ); # load Pari, too - my $anti_matter = Math::BigFloat->bone()+4; # now use Pari - -This will create objects with numbers stored in two different backend libraries, -and B will happen when you use these together: - - my $flash_and_bang = $matter + $anti_matter; # Don't do this! - =over =item stringify, bstr() @@ -6822,10 +6909,12 @@ the same terms as Perl itself. =head1 SEE ALSO -L and L as well as the backends -L, L, and L. +L and L as well as the backend libraries +L, L, and L, +L, and L. -The pragmas L, L and L. +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. =head1 AUTHORS diff --git a/cpan/Math-BigInt/lib/Math/BigInt.pm b/cpan/Math-BigInt/lib/Math/BigInt.pm index fee4286bdb2c..d99ca6b9a137 100644 --- a/cpan/Math-BigInt/lib/Math/BigInt.pm +++ b/cpan/Math-BigInt/lib/Math/BigInt.pm @@ -23,7 +23,7 @@ use warnings; use Carp qw< carp croak >; use Scalar::Util qw< blessed refaddr >; -our $VERSION = '1.999842'; +our $VERSION = '2.000000'; $VERSION =~ tr/_//d; require Exporter; @@ -236,7 +236,7 @@ my $nan = 'NaN'; # constants for easier life my $DEFAULT_LIB = 'Math::BigInt::Calc'; my $LIB; -# Has import() been called yet? Needed to make "require" work. +# Has import() been called yet? This variable is needed to make "require" work. my $IMPORT = 0; @@ -714,6 +714,10 @@ sub from_dec { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_dec'); @@ -750,6 +754,10 @@ sub from_hex { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_hex'); @@ -786,6 +794,10 @@ sub from_oct { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_oct'); @@ -822,6 +834,10 @@ sub from_bin { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bin'); @@ -858,6 +874,10 @@ sub from_bytes { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bytes'); @@ -881,6 +901,10 @@ sub from_base { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_base'); @@ -925,6 +949,10 @@ sub from_base_num { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_base_num'); @@ -980,7 +1008,9 @@ sub bzero { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1030,7 +1060,9 @@ sub bone { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1094,7 +1126,9 @@ sub binf { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1159,7 +1193,9 @@ sub bnan { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1225,6 +1261,10 @@ sub bpi { my $class = $selfref || $self; my @r = @_; # rounding paramters + # Make "require" work. + + $class -> import() if $IMPORT == 0; + if ($selfref) { # bpi() called as an instance method return $self if $self -> modify('bpi'); } else { # bpi() called as a class method @@ -1602,8 +1642,12 @@ sub babs { return $x if $x->modify('babs'); - return $upgrade -> babs($x, @r) - if defined($upgrade) && !$x->isa(__PACKAGE__) && !$x -> isa($upgrade); + # This call to the upgrade class must either be commented out or the method + # must be implemented in the upgrade class(es) to avoid infinite recursion. + # It doesn't help to check whether $x isa $upgrade, because there might be + # several levels of upgrading. Also see the test file t/upgrade2.t + #return $upgrade -> babs($x, @r) + # if defined($upgrade) && !$x->isa(__PACKAGE__); $x->{sign} =~ s/^-/+/; @@ -1616,8 +1660,12 @@ sub bsgn { return $x if $x->modify('bsgn'); - return $upgrade -> bsgn($x, @r) - if defined($upgrade) && !$x->isa(__PACKAGE__) && !$x -> isa($upgrade); + # This call to the upgrade class must either be commented out or the method + # must be implemented in the upgrade class(es) to avoid infinite recursion. + # It doesn't help to check whether $x isa $upgrade, because there might be + # several levels of upgrading. Also see the test file t/upgrade2.t + #return $upgrade -> bsgn($x, @r) + # if defined($upgrade) && !$x->isa(__PACKAGE__); return $x -> bone("+", @r) if $x -> is_pos(); return $x -> bone("-", @r) if $x -> is_neg(); @@ -2708,6 +2756,20 @@ sub bpow { $x -> round(@r); } +sub binv { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + return $x if $x -> modify('binv'); + + return $x -> binf("+", @r) if $x -> is_zero(); + return $x -> bzero(@r) if $x -> is_inf(); + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> round(@r) if $x -> is_one("+") || $x -> is_one("-"); + + return $upgrade -> binv($x, @r) if defined $upgrade; + $x -> bzero(@r); +} + sub blog { # Return the logarithm of the operand. If a second operand is defined, that # value is used as the base, otherwise the base is assumed to be Euler's @@ -3398,42 +3460,92 @@ sub blsft { return $x if $x -> modify('blsft'); + # The default base is 2. + $b = 2 unless defined $b; $b = $class -> new($b) unless defined(blessed($b)); + # Handle "foreign" objects. + return $upgrade -> blsft($x, $y, $b, @r) if defined($upgrade) && (!$x -> isa(__PACKAGE__) || !$y -> isa(__PACKAGE__) || !$b -> isa(__PACKAGE__)); - return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); + # Handle NaN cases. + + return $x -> bnan(@r) + if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); # blsft($x, -$y, $b) = brsft($x, $y, $b) return $x -> brsft($y -> copy() -> bneg(), $b, @r) if $y -> is_neg(); - return $x -> bmul($b -> bpow($y)); - - # Base $b = 1 changes nothing, not even when $b = Inf. Shifting zero places - # ($y = 0) doesn't change anything either. - return $x -> bround(@r) if $b -> is_one("+") || $y -> is_zero(); + # Now handle all cases where at least one operand is ±Inf or the result + # will be ±Inf or NaN. - # Shifting infinitely far to the left. if ($y -> is_inf("+")) { - return $x -> binf("+", @r) if $x -> is_pos(); - return $x -> binf("-", @r) if $x -> is_neg(); - return $x -> bnan(@r); # Inf * 0 = NaN + if ($b -> is_one("-")) { + return $x -> bnan(@r); + } elsif ($b -> is_one("+")) { + return $x -> round(@r); + } elsif ($b -> is_zero()) { + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> bzero(@r); + } else { + return $x -> binf("-", @r) if $x -> is_negative(); + return $x -> binf("+", @r) if $x -> is_positive(); + return $x -> bnan(@r); + } } - # At this point we know that $b > 1, so we are essentially computing 0 * - # Inf = NaN. - return $x -> bnan(@r) if $x -> is_zero() && $y -> is_inf("+"); + if ($b -> is_inf()) { + return $x -> bnan(@r) if $x -> is_zero() || $y -> is_zero(); + if ($b -> is_inf("-")) { + return $x -> binf("+", @r) + if ($x -> is_negative() && $y -> is_odd() || + $x -> is_positive() && $y -> is_even()); + return $x -> binf("-", @r); + } else { + return $x -> binf("-", @r) if $x -> is_negative(); + return $x -> binf("+", @r); + } + } - # Handle trivial zero case. - return $x -> bzero(@r) if $x -> is_zero(); + if ($b -> is_zero()) { + return $x -> round(@r) if $y -> is_zero(); + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> bzero(@r); + } - return $x -> binf("+", @r) if $y -> is_inf("+"); - return $x -> bzero(@r) if $x -> is_zero(); + if ($x -> is_inf()) { + if ($b -> is_negative()) { + if ($x -> is_inf("-")) { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("+", @r); + } + } else { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("-", @r); + } + } + } else { + return $x -> round(@r); + } + } + + # At this point, we know that both the input and the output is finite. + # Handle some trivial cases. + + return $x -> round(@r) if $x -> is_zero() || $y -> is_zero() + || $b -> is_one("+") + || $b -> is_one("-") && $y -> is_even(); + + return $x -> bneg(@r) if $b -> is_one("-") && $y -> is_odd(); # While some of the libraries support an arbitrarily large base, not all of # them do, so rather than returning an incorrect result in those cases, @@ -3443,8 +3555,14 @@ sub blsft { if ($x -> bcmp($uintmax) > 0) { $x = $x -> bmul($b -> bpow($y)); } else { + my $neg = 0; + if ($b -> is_negative()) { + $neg = 1 if $y -> is_odd(); + $b = $b -> babs(); + } $b = $b -> numify(); $x -> {value} = $LIB -> _lsft($x -> {value}, $y -> {value}, $b); + $x -> {sign} =~ tr/+-/-+/ if $neg; } $x -> round(@r); } @@ -3453,7 +3571,7 @@ sub brsft { # (BINT or num_str, BINT or num_str) return BINT # compute $x >> $y, base $n - my ($class, $x, $y, $b, @r) = (ref($_[0]), @_); + my ($class, $x, $y, $b, @r); # Objectify the base only when it is defined, since an undefined base, as # in $x->blsft(3) or $x->blog(3, undef) means use the default base 2. @@ -3470,27 +3588,103 @@ sub brsft { return $x if $x -> modify('brsft'); + # The default base is 2. + $b = 2 unless defined $b; $b = $class -> new($b) unless defined(blessed($b)); + # Handle "foreign" objects. + return $upgrade -> brsft($x, $y, $b, @r) if defined($upgrade) && (!$x -> isa(__PACKAGE__) || !$y -> isa(__PACKAGE__) || !$b -> isa(__PACKAGE__)); - return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); + # Handle NaN cases. + + return $x -> bnan(@r) + if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); # brsft($x, -$y, $b) = blsft($x, $y, $b) return $x -> blsft($y -> copy() -> bneg(), $b, @r) if $y -> is_neg(); - return $x -> round(@r) if $y -> is_zero(); - return $x -> bzero(@r) if $x -> is_zero(); + # Now handle all cases where at least one operand is ±Inf or the result + # will be ±Inf or NaN. - # Shifting right by a positive amount might lead to a non-integer result. + if ($b -> is_inf()) { + return $x -> bnan(@r) if $x -> is_inf() || $y -> is_zero(); + if ($b -> is_inf("+")) { + if ($x -> is_negative()) { + return $x -> bone("-", @r); + } else { + return $x -> bzero(@r); + } + } else { + if ($x -> is_negative()) { + return $y -> is_odd() ? $x -> bzero(@r) + : $x -> bone("-", @r); + } elsif ($x -> is_positive()) { + return $y -> is_odd() ? $x -> bone("-", @r) + : $x -> bzero(@r); + } else { + return $x -> bzero(@r); + } + } + } - return $upgrade -> brsft($x, $y, $b, @r) - if defined($upgrade) && $y -> is_pos(); + if ($b -> is_zero()) { + return $x -> round(@r) if $y -> is_zero(); + return $x -> bnan(@r) if $x -> is_zero(); + return $x -> is_negative() ? $x -> binf("-", @r) + : $x -> binf("+", @r); + } + + if ($y -> is_inf("+")) { + if ($b -> is_one("-")) { + return $x -> bnan(@r); + } elsif ($b -> is_one("+")) { + return $x -> round(@r); + } else { + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> is_negative() ? $x -> bone("-", @r) + : $x -> bzero(@r); + } + } + + if ($x -> is_inf()) { + if ($b -> is_negative()) { + if ($x -> is_inf("-")) { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("+", @r); + } + } else { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("-", @r); + } + } + } else { + return $x -> round(@r); + } + } + + # At this point, we know that both the input and the output is finite. + # Handle some trivial cases. + + return $x -> round(@r) if $x -> is_zero() || $y -> is_zero() + || $b -> is_one("+") + || $b -> is_one("-") && $y -> is_even(); + + return $x -> bneg(@r) if $b -> is_one("-") && $y -> is_odd(); + + # We know that $y is positive. Shifting right by a positive amount might + # lead to a non-integer result. + + return $upgrade -> brsft($x, $y, $b, @r) if defined($upgrade); # This only works for negative numbers when shifting in base 2. if ($x -> is_neg() && $b -> bcmp("2") == 0) { @@ -3519,7 +3713,7 @@ sub brsft { # division. my $uintmax = ~0; - if ($x -> bcmp($uintmax) > 0 || $x -> is_neg()) { + if ($x -> bcmp($uintmax) > 0 || $x -> is_neg() || $b -> is_negative()) { $x = $x -> bdiv($b -> bpow($y)); } else { $b = $b -> numify(); @@ -6116,6 +6310,7 @@ Math::BigInt - arbitrary size integer math package $x->btmod($y); # modulus (truncated) $x->bmodinv($mod); # modular multiplicative inverse $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod) + $x->binv() # inverse (1/$x) $x->bpow($y); # power of arguments (x ** y) $x->blog(); # logarithm of $x to base e (Euler's number) $x->blog($base); # logarithm of $x to base $base (e.g., base 2) @@ -6923,6 +7118,12 @@ Multiply $x by $y, and then add $z to the result, This method was added in v1.87 of Math::BigInt (June 2007). +=item binv() + + $x->binv(); + +Invert the value of $x, i.e., compute 1/$x. + =item bdiv() $x->bdiv($y); # divide, set $x to quotient @@ -8780,11 +8981,12 @@ the same terms as Perl itself. =head1 SEE ALSO -L and L as well as the backends -L, L, and L. +L and L as well as the backend libraries +L, L, and L, +L, and L. -The pragmas L, L and L also might be of interest -because they solve the autoupgrading/downgrading issue, at least partly. +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. =head1 AUTHORS diff --git a/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm b/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm index f00f508861be..7ee112ee6745 100644 --- a/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm +++ b/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm @@ -7,7 +7,7 @@ use warnings; use Carp qw< carp croak >; use Math::BigInt::Lib; -our $VERSION = '1.999842'; +our $VERSION = '2.000000'; $VERSION =~ tr/_//d; our @ISA = ('Math::BigInt::Lib'); diff --git a/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm b/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm index 0516d925bbc0..b2da9c8c86ca 100644 --- a/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm +++ b/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm @@ -4,7 +4,7 @@ use 5.006001; use strict; use warnings; -our $VERSION = '1.999842'; +our $VERSION = '2.000000'; $VERSION =~ tr/_//d; use Carp; diff --git a/cpan/Math-BigRat/lib/Math/BigRat.pm b/cpan/Math-BigInt/lib/Math/BigRat.pm similarity index 91% rename from cpan/Math-BigRat/lib/Math/BigRat.pm rename to cpan/Math-BigInt/lib/Math/BigRat.pm index 0d0f24679579..348081305d28 100644 --- a/cpan/Math-BigRat/lib/Math/BigRat.pm +++ b/cpan/Math-BigInt/lib/Math/BigRat.pm @@ -16,12 +16,13 @@ use 5.006; use strict; use warnings; -use Carp qw< carp croak >; -use Scalar::Util qw< blessed >; +use Carp qw< carp croak >; +use Scalar::Util qw< blessed >; use Math::BigFloat (); -our $VERSION = '0.2624'; +our $VERSION = '2.000000'; +$VERSION =~ tr/_//d; our @ISA = qw(Math::BigFloat); @@ -49,29 +50,29 @@ use overload '**' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bpow($_[0]) : $_[0] -> copy() -> bpow($_[1]); }, - '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blsft($_[0]) - : $_[0] -> copy() -> blsft($_[1]); }, + '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bblsft($_[0]) + : $_[0] -> copy() -> bblsft($_[1]); }, - '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> brsft($_[0]) - : $_[0] -> copy() -> brsft($_[1]); }, + '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bbrsft($_[0]) + : $_[0] -> copy() -> bbrsft($_[1]); }, # overload key: assign - '+=' => sub { $_[0]->badd($_[1]); }, + '+=' => sub { $_[0] -> badd($_[1]); }, - '-=' => sub { $_[0]->bsub($_[1]); }, + '-=' => sub { $_[0] -> bsub($_[1]); }, - '*=' => sub { $_[0]->bmul($_[1]); }, + '*=' => sub { $_[0] -> bmul($_[1]); }, - '/=' => sub { scalar $_[0]->bdiv($_[1]); }, + '/=' => sub { scalar $_[0] -> bdiv($_[1]); }, - '%=' => sub { $_[0]->bmod($_[1]); }, + '%=' => sub { $_[0] -> bmod($_[1]); }, - '**=' => sub { $_[0]->bpow($_[1]); }, + '**=' => sub { $_[0] -> bpow($_[1]); }, - '<<=' => sub { $_[0]->blsft($_[1]); }, + '<<=' => sub { $_[0] -> bblsft($_[1]); }, - '>>=' => sub { $_[0]->brsft($_[1]); }, + '>>=' => sub { $_[0] -> bbrsft($_[1]); }, # 'x=' => sub { }, @@ -224,7 +225,14 @@ $_trap_inf = 0; # are infs ok? set w/ config() my $LIB = 'Math::BigInt::Calc'; my $nan = 'NaN'; -#my $class = 'Math::BigRat'; + +# Has import() been called yet? This variable is needed to make "require" work. + +my $IMPORT = 0; + +# Compare the following function with @ISA above. This inheritance mess needs a +# clean up. When doing so, also consider the BEGIN block and the AUTOLOAD code. +# Fixme! sub isa { return 0 if $_[1] =~ /^Math::Big(Int|Float)/; # we aren't @@ -238,6 +246,10 @@ sub new { my $protoref = ref $proto; my $class = $protoref || $proto; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Check the way we are called. if ($protoref) { @@ -572,6 +584,10 @@ sub bnan { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + $self = bless {}, $class unless $selfref; if ($_trap_nan) { @@ -595,6 +611,10 @@ sub binf { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + $self = bless {}, $class unless $selfref; my $sign = shift(); @@ -621,6 +641,10 @@ sub bone { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + my $sign = shift(); $sign = '+' unless defined($sign) && $sign eq '-'; @@ -642,6 +666,10 @@ sub bzero { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + return $downgrade -> bzero() if defined $downgrade; $self = bless {}, $class unless $selfref; @@ -1207,14 +1235,13 @@ sub binc { } sub binv { - my $x = shift; - my @r = @_; + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - return $x if $x->modify('binv'); + return $x if $x -> modify('binv'); - return $x if $x -> is_nan(); - return $x -> bzero() if $x -> is_inf(); - return $x -> binf("+") if $x -> is_zero(); + return $x -> round(@r) if $x -> is_nan(); + return $x -> bzero(@r) if $x -> is_inf(); + return $x -> binf("+", @r) if $x -> is_zero(); ($x -> {_n}, $x -> {_d}) = ($x -> {_d}, $x -> {_n}); $x -> round(@r); @@ -1896,6 +1923,90 @@ sub brsft { $x -> bdiv($b -> bpow($y)); } +############################################################################### +# Bitwise methods +############################################################################### + +# Bitwise left shift. + +sub bblsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bblsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # Convert to our class without downgrading. + + my $xrat = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + } else { + $x = $xrat; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + +# Bitwise right shift. + +sub bbrsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bbrsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # Convert to our class without downgrading. + + my $xrat = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + } else { + $x = $xrat; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + sub band { my $x = shift; my $xref = ref($x); @@ -1909,13 +2020,15 @@ sub band { my @r = @_; - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> band($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; + $xint = $xint -> band($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; return $x -> round(@r); } @@ -1933,13 +2046,15 @@ sub bior { my @r = @_; - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bior($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; + $xint = $xint -> bior($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; return $x -> round(@r); } @@ -1957,13 +2072,15 @@ sub bxor { my @r = @_; - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bxor($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; + $xint = $xint -> bxor($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; return $x -> round(@r); } @@ -1977,13 +2094,13 @@ sub bnot { my @r = @_; - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bnot(); - $xtmp = $class -> new($xtmp); # back to Math::BigRat + my $xint = $x -> as_int(); # to Math::BigInt + $xint = $xint -> bnot(); - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; return $x -> round(@r); } @@ -2257,6 +2374,54 @@ sub as_float { return $y; } +sub to_hex { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_hex($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + +sub to_oct { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_oct($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + +sub to_bin { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_bin($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + sub as_bin { my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); @@ -2287,6 +2452,55 @@ sub as_oct { ############################################################################## +# Create a Math::BigRat from a decimal string. This is an equivalent to +# from_hex(), from_oct(), and from_bin(). It is like new() except that it does +# not accept anything but a string representing a finite decimal number. + +sub from_dec { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + # Don't modify constant (read-only) objects. + + return $self if $selfref && $self->modify('from_dec'); + + my $str = shift; + my @r = @_; + + # If called as a class method, initialize a new object. + + $self = bless {}, $class unless $selfref; + + if (my @parts = $class -> _dec_str_to_flt_lib_parts($str)) { + my ($mant_sgn, $mant_abs, $expo_sgn, $expo_abs) = @parts; + $self->{sign} = $mant_sgn; + $self->{_n} = $mant_abs; + if ($expo_sgn eq "+") { + $self->{_n} = $LIB -> _lsft($self->{_n}, $expo_abs, 10); + $self->{_d} = $LIB -> _one(); + } else { + $self->{_d} = $LIB -> _1ex($mant_abs); + } + + my $gcd = $LIB -> _gcd($LIB -> _copy($self->{_n}), $self->{_d}); + if (!$LIB -> _is_one($gcd)) { + $self -> {_n} = $LIB -> _div($self->{_n}, $gcd); + $self -> {_d} = $LIB -> _div($self->{_d}, $gcd); + } + + return $downgrade -> new($self -> bstr(), @r) + if defined($downgrade) && $self -> is_int(); + return $self; + } + + return $self -> bnan(@r); +} + sub from_hex { my $class = shift; @@ -3102,9 +3316,8 @@ Binary floating point literals: =head1 BUGS Please report any bugs or feature requests to -C, or through the web interface at -L -(requires login). +C, or through the web interface at +L (requires login). We will be notified, and then you'll automatically be notified of progress on your bug as I make changes. @@ -3112,7 +3325,7 @@ your bug as I make changes. You can find documentation for this module with the perldoc command. - perldoc Math::BigRat + perldoc Math::BigInt You can also look for information at: @@ -3120,23 +3333,19 @@ You can also look for information at: =item * GitHub -L +L =item * RT: CPAN's request tracker -L +L =item * MetaCPAN -L +L =item * CPAN Testers Matrix -L - -=item * CPAN Ratings - -L +L =back @@ -3147,8 +3356,12 @@ the same terms as Perl itself. =head1 SEE ALSO -L, L and L as well as the backends -L, L, and L. +L and L as well as the backend libraries +L, L, and L, +L, and L. + +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. =head1 AUTHORS diff --git a/cpan/Math-BigRat/t/Math/BigRat/Test.pm b/cpan/Math-BigInt/t/Math/BigRat/Test.pm similarity index 100% rename from cpan/Math-BigRat/t/Math/BigRat/Test.pm rename to cpan/Math-BigInt/t/Math/BigRat/Test.pm diff --git a/cpan/Math-BigRat/t/big_ap.t b/cpan/Math-BigInt/t/big_ap.t similarity index 100% rename from cpan/Math-BigRat/t/big_ap.t rename to cpan/Math-BigInt/t/big_ap.t diff --git a/cpan/Math-BigRat/t/bigfltrt.t b/cpan/Math-BigInt/t/bigfltrt.t similarity index 100% rename from cpan/Math-BigRat/t/bigfltrt.t rename to cpan/Math-BigInt/t/bigfltrt.t diff --git a/cpan/Math-BigRat/t/bigrat.t b/cpan/Math-BigInt/t/bigrat.t similarity index 100% rename from cpan/Math-BigRat/t/bigrat.t rename to cpan/Math-BigInt/t/bigrat.t diff --git a/cpan/Math-BigRat/t/bigratpm.inc b/cpan/Math-BigInt/t/bigratpm.inc similarity index 100% rename from cpan/Math-BigRat/t/bigratpm.inc rename to cpan/Math-BigInt/t/bigratpm.inc diff --git a/cpan/Math-BigRat/t/bigratpm.t b/cpan/Math-BigInt/t/bigratpm.t similarity index 100% rename from cpan/Math-BigRat/t/bigratpm.t rename to cpan/Math-BigInt/t/bigratpm.t diff --git a/cpan/Math-BigRat/t/bigratup.t b/cpan/Math-BigInt/t/bigratup.t similarity index 100% rename from cpan/Math-BigRat/t/bigratup.t rename to cpan/Math-BigInt/t/bigratup.t diff --git a/cpan/Math-BigRat/t/bitwise.t b/cpan/Math-BigInt/t/bitwise-mbr.t similarity index 100% rename from cpan/Math-BigRat/t/bitwise.t rename to cpan/Math-BigInt/t/bitwise-mbr.t diff --git a/cpan/Math-BigInt/t/downgrade.t b/cpan/Math-BigInt/t/downgrade-mbi-mbf.t similarity index 100% rename from cpan/Math-BigInt/t/downgrade.t rename to cpan/Math-BigInt/t/downgrade-mbi-mbf.t diff --git a/cpan/Math-BigRat/t/downgrade.t b/cpan/Math-BigInt/t/downgrade-mbi-mbr.t similarity index 100% rename from cpan/Math-BigRat/t/downgrade.t rename to cpan/Math-BigInt/t/downgrade-mbi-mbr.t diff --git a/cpan/Math-BigRat/t/hang.t b/cpan/Math-BigInt/t/hang-mbr.t similarity index 100% rename from cpan/Math-BigRat/t/hang.t rename to cpan/Math-BigInt/t/hang-mbr.t diff --git a/cpan/Math-BigInt/t/req_mbf0.t b/cpan/Math-BigInt/t/req_mbf0.t deleted file mode 100644 index 976cb0c26372..000000000000 --- a/cpan/Math-BigInt/t/req_mbf0.t +++ /dev/null @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bzero() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bzero(); $x++; -is($x, 1, '$x is 1'); - -# all tests done diff --git a/cpan/Math-BigInt/t/req_mbf1.t b/cpan/Math-BigInt/t/req_mbf1.t deleted file mode 100644 index 74ad48bca0d8..000000000000 --- a/cpan/Math-BigInt/t/req_mbf1.t +++ /dev/null @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bone() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bone(); -is($x, 1, '$x is 1'); - -# all tests done diff --git a/cpan/Math-BigInt/t/req_mbfa.t b/cpan/Math-BigInt/t/req_mbfa.t deleted file mode 100644 index a436aa27a25c..000000000000 --- a/cpan/Math-BigInt/t/req_mbfa.t +++ /dev/null @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bnan() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bnan(1); -is($x, 'NaN', '$x is NaN'); - -# all tests done diff --git a/cpan/Math-BigInt/t/req_mbfi.t b/cpan/Math-BigInt/t/req_mbfi.t deleted file mode 100644 index 69c82c0f0858..000000000000 --- a/cpan/Math-BigInt/t/req_mbfi.t +++ /dev/null @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then binf() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->binf(); -is($x, 'inf', '$x is inf'); - -# all tests done diff --git a/cpan/Math-BigInt/t/req_mbfn.t b/cpan/Math-BigInt/t/req_mbfn.t deleted file mode 100644 index eef0e011af3b..000000000000 --- a/cpan/Math-BigInt/t/req_mbfn.t +++ /dev/null @@ -1,16 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then new() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->new(1); -++$x; -is($x, 2, '$x is 2'); - -# all tests done diff --git a/cpan/Math-BigInt/t/req_mbfw.t b/cpan/Math-BigInt/t/req_mbfw.t deleted file mode 100644 index 2e7ece75b2de..000000000000 --- a/cpan/Math-BigInt/t/req_mbfw.t +++ /dev/null @@ -1,29 +0,0 @@ -# -*- mode: perl; -*- - -# check that requiring Math::BigFloat and then calling import() works - -use strict; -use warnings; - -use Test::More tests => 3; - -use lib 't'; - -# 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/cpan/Math-BigInt/t/require.t b/cpan/Math-BigInt/t/require.t deleted file mode 100644 index 32fde97158d1..000000000000 --- a/cpan/Math-BigInt/t/require.t +++ /dev/null @@ -1,17 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigInt works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigInt; - -my $x = Math::BigInt->new(1); -++$x; - -is($x, 2, '$x is 2'); - -# all tests done diff --git a/cpan/Math-BigRat/t/rt121139.t b/cpan/Math-BigInt/t/rt121139.t similarity index 100% rename from cpan/Math-BigRat/t/rt121139.t rename to cpan/Math-BigInt/t/rt121139.t diff --git a/cpan/Math-BigInt/t/trap.t b/cpan/Math-BigInt/t/trap.t index 28d75cf6d8cf..cf3b7e8ecdaa 100644 --- a/cpan/Math-BigInt/t/trap.t +++ b/cpan/Math-BigInt/t/trap.t @@ -5,64 +5,98 @@ use strict; use warnings; -use Test::More tests => 43; - -use Math::BigInt; -use Math::BigFloat; +use Test::More tests => 90; my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; -my ($cfg, $x); +my $mbr = 'Math::BigRat'; + +use_ok($mbi); +use_ok($mbf); +use_ok($mbr); + +my $x; + +foreach my $class ($mbi, $mbf, $mbr) { -foreach my $class ($mbi, $mbf) { - # can do and defaults are okay? - ok($class->can('config'), 'can config()'); + # can do? + can_ok($class, 'config'); + + ########################################################################### + # Default values. + ########################################################################### + + # defaults are okay? is($class->config("trap_nan"), 0, 'trap_nan defaults to 0'); is($class->config("trap_inf"), 0, 'trap_inf defaults to 0'); + ########################################################################### + # Trap NaN. + ########################################################################### + # can set? - $cfg = $class->config( trap_nan => 1 ); - is($cfg->{trap_nan}, 1, 'trap_nan now true'); + $class->config( trap_nan => 1 ); + is($class->config("trap_nan"), 1, qq|$class->config( trap_nan => 1 );|); + + # can reset? + $class->config( trap_nan => 0 ); + is($class->config("trap_nan"), 0, qq|$class->config( trap_nan => 0 );|); + + # can set via hash ref? + $class->config( { trap_nan => 1 } ); + is($class->config("trap_nan"), 1, qq|$class->config( { trap_nan => 1 } );|); + + # 0/0 => NaN + $x = $class->new("0"); + eval { $x->bdiv(0); }; + like($@, qr/^Tried to /, qq|\$x = $class->new("0"); \$x->bdiv(0);|); + + # new() didn't modify $x + is($x, 0, qq|\$x = $class->new("0"); \$x->bdiv(0);|); # also test that new() still works normally - eval ("\$x = \$class->new('42'); \$x->bnan();"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('42'); $x->bnan(); }; + like($@, qr/^Tried to /, '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'); + $class->config( trap_nan => 0 ); + is($class->config("trap_nan"), 0, qq|$class->config( trap_nan => 0 );|); + + ########################################################################### + # Trap inf. + ########################################################################### # can set? - $cfg = $class->config( trap_inf => 1 ); - is($cfg->{trap_inf}, 1, 'trap_inf enabled'); + $class->config( trap_inf => 1 ); + is($class->config("trap_inf"), 1, 'trap_inf enabled'); - eval ("\$x = \$class->new('4711'); \$x->binf();"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('4711'); $x->binf(); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); - eval ("\$x = \$class->new('inf');"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('inf'); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); - eval ("\$x = \$class->new('-inf');"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('-inf'); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); # +$x/0 => +inf - eval ("\$x = \$class->new('4711'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('4711'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); # -$x/0 => -inf - eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('-0815'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, '-815', '$x after new not modified'); - $cfg = $class->config( trap_nan => 1 ); + $class->config( trap_nan => 1 ); # 0/0 => NaN - eval ("\$x = \$class->new('0'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('0'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, '0', '$x after new not modified'); } @@ -70,16 +104,40 @@ foreach my $class ($mbi, $mbf) { # Math::BigInt $x = Math::BigInt->new(2); -eval ("\$x = \$mbi->new('0.1');"); +eval { $x = $mbi->new('0.1'); }; is($x, 2, 'never modified since it dies'); -eval ("\$x = \$mbi->new('0a.1');"); + +eval { $x = $mbi->new('0a.1'); }; is($x, 2, 'never modified since it dies'); ############################################################################## # Math::BigFloat $x = Math::BigFloat->new(2); -eval ("\$x = \$mbf->new('0.1a');"); +eval { $x = $mbf->new('0.1a'); }; is($x, 2, 'never modified since it dies'); +############################################################################## +# BigRat + +Math::BigRat->config(trap_nan => 1, + trap_inf => 1); + +for my $trap (qw/ 0.1a +inf inf -inf /) { + my $x = Math::BigRat->new('7/4'); + + note(""); # this is just for some space in the output + + # In each of the cases below, $x is not modified, because the code dies. + + eval { $x = $mbr->new("$trap"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap");|); + + eval { $x = $mbr->new("$trap"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap");|); + + eval { $x = $mbr->new("$trap/7"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap/7");|); +} + # all tests done diff --git a/cpan/Math-BigInt/t/upgrade2.t b/cpan/Math-BigInt/t/upgrade2.t index 28ecdbb50b63..d077eaf2d14e 100644 --- a/cpan/Math-BigInt/t/upgrade2.t +++ b/cpan/Math-BigInt/t/upgrade2.t @@ -5,7 +5,7 @@ use warnings; # Test 2 levels of upgrade classes. This used to cause a segv. -use Test::More tests => 1; +use Test::More tests => 9; use Math::BigInt upgrade => 'Math::BigFloat'; use Math::BigFloat upgrade => 'Math::BigMouse'; @@ -16,3 +16,56 @@ sub Math::BigMouse::bsqrt {}; () = sqrt Math::BigInt->new(2); pass('sqrt on a big int does not segv if there are 2 upgrade levels'); + +# Math::BigRat inherits from Math::BigFloat, which inherits from Math::BigInt. +# Typically, methods call the upgrade version if upgrading is defined and the +# argument is an unknown type. This will call infinite recursion for methods +# that are not implemented in the upgrade class. + +use Math::BigRat; + +Math::BigFloat -> upgrade("Math::BigRat"); +Math::BigFloat -> downgrade(undef); + +Math::BigRat -> upgrade(undef); +Math::BigRat -> downgrade(undef); + +# Input is a scalar. + +note 'Math::BigRat -> babs("2");'; +() = Math::BigRat -> babs("2"); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn("2");'; +() = Math::BigRat -> bsgn("2"); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigInt. + +note 'Math::BigRat -> babs(Math::BigInt -> new("2"));'; +() = Math::BigRat -> babs(Math::BigInt -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigInt -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigInt -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigFloat. + +note 'Math::BigRat -> babs(Math::BigFloat -> new("2"));'; +() = Math::BigRat -> babs(Math::BigFloat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigFloat -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigFloat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigRat. + +note 'Math::BigRat -> babs(Math::BigRat -> new("2"));'; +() = Math::BigRat -> babs(Math::BigRat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigRat -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigRat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); diff --git a/cpan/Math-BigInt/t/use_lib1.t b/cpan/Math-BigInt/t/use_lib1.t deleted file mode 100644 index eb12b91fffc8..000000000000 --- a/cpan/Math-BigInt/t/use_lib1.t +++ /dev/null @@ -1,18 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigFloat lib => 'BareCalc'; # loads "BareCalc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); diff --git a/cpan/Math-BigInt/t/use_lib2.t b/cpan/Math-BigInt/t/use_lib2.t deleted file mode 100644 index d3a7b45165f6..000000000000 --- a/cpan/Math-BigInt/t/use_lib2.t +++ /dev/null @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt; # loads "Calc" -use Math::BigFloat lib => 'BareCalc'; # ignores "BareCalc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::Calc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); diff --git a/cpan/Math-BigInt/t/use_lib3.t b/cpan/Math-BigInt/t/use_lib3.t deleted file mode 100644 index bcf7967d199d..000000000000 --- a/cpan/Math-BigInt/t/use_lib3.t +++ /dev/null @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt lib => 'BareCalc'; # ignores "BareCalc" -use Math::BigFloat; - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); diff --git a/cpan/Math-BigInt/t/use_lib4.t b/cpan/Math-BigInt/t/use_lib4.t deleted file mode 100644 index 190d7bbf1724..000000000000 --- a/cpan/Math-BigInt/t/use_lib4.t +++ /dev/null @@ -1,20 +0,0 @@ -# -*- mode: perl; -*- - -# 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 warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt lib => 'BareCalc'; # loads "BareCalc" -use Math::BigFloat lib => 'Calc'; # ignores "Calc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); diff --git a/cpan/Math-BigInt/t/use_lib5.t b/cpan/Math-BigInt/t/use_lib5.t deleted file mode 100644 index 9fff6c859304..000000000000 --- a/cpan/Math-BigInt/t/use_lib5.t +++ /dev/null @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigFloat lib => 'BareCalc'; # loads "BareCalc" -use Math::BigInt; - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); diff --git a/cpan/Math-BigInt/t/use_lib6.t b/cpan/Math-BigInt/t/use_lib6.t deleted file mode 100644 index cd0aea77744f..000000000000 --- a/cpan/Math-BigInt/t/use_lib6.t +++ /dev/null @@ -1,16 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 1; - -use Math::BigInt lib => 'BareCalc'; # loads "BareCalc" -eval "use Math::BigFloat only => 'foobar';"; # ignores "foobar" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); diff --git a/cpan/Math-BigRat/t/badd-mbr.t b/cpan/Math-BigRat/t/badd-mbr.t deleted file mode 100644 index 1f96200736f8..000000000000 --- a/cpan/Math-BigRat/t/badd-mbr.t +++ /dev/null @@ -1,164 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 173; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($xval, $yval, $zval) = split /:/; - my ($x, $y, $got, @got); - - for my $context_is_scalar (0, 1) { - for my $y_is_scalar (0, 1) { - - my $test = qq|\$x = $class -> new("$xval");|; - - $test .= $y_is_scalar - ? qq| \$y = "$yval";| - : qq| \$y = $class -> new("$yval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$x -> badd(\$y);| - : qq| \@got = \$x -> badd(\$y);|; - - my $desc = "badd() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - $desc .= $y_is_scalar ? " with y as scalar" : " with y as object"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 7 : 8; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($got -> bstr(), $zval, - "'$test' output arg has the right value"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar @got, '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $zval, - "'$test' output arg has the right value"); - } - - # Check the invocand. - - is(ref($x), $class, - "'$test' invocand is still a $class"); - - is($x -> bstr(), $zval, - "'$test' invocand has the right value"); - - # Check the input argument. - - if ($y_is_scalar) { - - is(ref($y), '', - "'$test' second input arg is still a scalar"); - - is($y, $yval, - "'$test' second input arg is unmodified"); - - } else { - - is(ref($y), $class, - "'$test' second input arg is still a $class"); - - is($y -> bstr(), $yval, - "'$test' second input arg is unmodified"); - } - }; - } - } -} - -__DATA__ - -# x and/or y is NaN - -NaN:NaN:NaN - -NaN:-inf:NaN -NaN:-3:NaN -NaN:0:NaN -NaN:3:NaN -NaN:inf:NaN - --inf:NaN:NaN --3:NaN:NaN -0:NaN:NaN -3:NaN:NaN -inf:NaN:NaN - -# x = inf - -inf:-inf:NaN -inf:-3:inf -inf:-2:inf -inf:-1:inf -inf:0:inf -inf:1:inf -inf:2:inf -inf:3:inf -inf:inf:inf - -# x = -inf - --inf:-inf:-inf --inf:-3:-inf --inf:-2:-inf --inf:-1:-inf --inf:0:-inf --inf:1:-inf --inf:2:-inf --inf:3:-inf --inf:inf:NaN - -# y = inf - --3:inf:inf --2:inf:inf --1:inf:inf -0:inf:inf -1:inf:inf -2:inf:inf -3:inf:inf - -# y = -inf - --3:-inf:-inf --2:-inf:-inf --1:-inf:-inf -0:-inf:-inf -1:-inf:-inf -2:-inf:-inf -3:-inf:-inf diff --git a/cpan/Math-BigRat/t/bigfltpm.inc b/cpan/Math-BigRat/t/bigfltpm.inc deleted file mode 100644 index b3dcaa606e5f..000000000000 --- a/cpan/Math-BigRat/t/bigfltpm.inc +++ /dev/null @@ -1,1673 +0,0 @@ -#include this file into another test for subclass testing... - -use strict; -use warnings; - -ok ($class->config()->{lib},$CL); - -my $z; - -while () - { - chomp; - $_ =~ 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 "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 "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 { 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; -&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 -# exercise _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 -&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/cpan/Math-BigRat/t/binv-mbr.t b/cpan/Math-BigRat/t/binv-mbr.t deleted file mode 100644 index dfba7fd6523a..000000000000 --- a/cpan/Math-BigRat/t/binv-mbr.t +++ /dev/null @@ -1,89 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 21; - -use Scalar::Util qw< refaddr >; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($xval, $yval) = split /:/; - my ($x, $got, @got); - - for my $context_is_scalar (0, 1) { - - my $test = qq|\$x = $class -> new("$xval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$x -> binv();| - : qq| \@got = \$x -> binv();|; - - my $desc = "binv() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 4 : 5; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($x -> bstr(), $yval, - "'$test' output arg has the right value"); - - is(refaddr($got), refaddr($x), - "'$test' output arg is the invocand"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar(@got), '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $yval, - "'$test' output arg has the right value"); - - is(refaddr($got[0]), refaddr($x), - "'$test' output arg is the invocand"); - } - }; - } -} - -__DATA__ - -NaN:NaN -inf:0 -5:1/5 -2:1/2 -1:1 -0:inf --1:-1 --2:-1/2 --5:-1/5 --inf:0 diff --git a/cpan/Math-BigRat/t/bnok-mbr.t b/cpan/Math-BigRat/t/bnok-mbr.t deleted file mode 100644 index 7de6365d91c9..000000000000 --- a/cpan/Math-BigRat/t/bnok-mbr.t +++ /dev/null @@ -1,1451 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 4957; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($nval, $kval, $nokval) = split /:/; - my ($n, $k, $got, @got); - - for my $context_is_scalar (0, 1) { - for my $k_is_scalar (0, 1) { - - my $test = qq|\$n = $class -> new("$nval");|; - - $test .= $k_is_scalar - ? qq| \$k = "$kval";| - : qq| \$k = $class -> new("$kval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$n -> bnok(\$k);| - : qq| \@got = \$n -> bnok(\$k);|; - - my $desc = "bnok() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - $desc .= $k_is_scalar ? " with k as scalar" : " with k as object"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 7 : 8; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($got -> bstr(), $nokval, - "'$test' output arg has the right value"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar @got, '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $nokval, - "'$test' output arg has the right value"); - } - - # Check the invocand. - - is(ref($n), $class, - "'$test' invocand is still a $class"); - - is($n -> bstr(), $nokval, - "'$test' invocand has the right value"); - - # Check the input argument. - - if ($k_is_scalar) { - - is(ref($k), '', - "'$test' second input arg is still a scalar"); - - is($k, $kval, - "'$test' second input arg is unmodified"); - - } else { - - is(ref($k), $class, - "'$test' second input arg is still a $class"); - - is($k -> bstr(), $kval, - "'$test' second input arg is unmodified"); - } - }; - } - } -} - -__DATA__ - -# n and/or k is NaN - -NaN:NaN:NaN -NaN:0:NaN -NaN:3:NaN -3:NaN:NaN -NaN:-3:NaN --3:NaN:NaN - -# n = inf - -inf:-inf:NaN -inf:-3:0 -inf:-2:0 -inf:-1:0 -inf:0:1 -inf:1:inf -inf:2:inf -inf:3:inf -inf:inf:NaN - -# n = -inf - --inf:-inf:NaN --inf:-3:0 --inf:-2:0 --inf:-1:0 --inf:0:1 --inf:1:-inf --inf:2:inf --inf:3:-inf --inf:inf:NaN - -# k = inf - --3:inf:NaN --2:inf:NaN --1:inf:NaN -0:inf:NaN -1:inf:NaN -2:inf:NaN -3:inf:NaN - -# k = -inf - --3:-inf:NaN --2:-inf:NaN --1:-inf:NaN -0:-inf:NaN -1:-inf:NaN -2:-inf:NaN -3:-inf:NaN - -# n = -15, k = n - 15 ... n + 15 - --15:-30:-77558760 --15:-29:40116600 --15:-28:-20058300 --15:-27:9657700 --15:-26:-4457400 --15:-25:1961256 --15:-24:-817190 --15:-23:319770 --15:-22:-116280 --15:-21:38760 --15:-20:-11628 --15:-19:3060 --15:-18:-680 --15:-17:120 --15:-16:-15 --15:-15:1 --15:-14:0 --15:-13:0 --15:-12:0 --15:-11:0 --15:-10:0 --15:-9:0 --15:-8:0 --15:-7:0 --15:-6:0 --15:-5:0 --15:-4:0 --15:-3:0 --15:-2:0 --15:-1:0 --15:0:1 --15:1:-15 --15:2:120 --15:3:-680 --15:4:3060 --15:5:-11628 --15:6:38760 --15:7:-116280 --15:8:319770 --15:9:-817190 --15:10:1961256 --15:11:-4457400 --15:12:9657700 --15:13:-20058300 --15:14:40116600 --15:15:-77558760 - -# n = -14, k = n - 15 ... n + 15 - --14:-29:-37442160 --14:-28:20058300 --14:-27:-10400600 --14:-26:5200300 --14:-25:-2496144 --14:-24:1144066 --14:-23:-497420 --14:-22:203490 --14:-21:-77520 --14:-20:27132 --14:-19:-8568 --14:-18:2380 --14:-17:-560 --14:-16:105 --14:-15:-14 --14:-14:1 --14:-13:0 --14:-12:0 --14:-11:0 --14:-10:0 --14:-9:0 --14:-8:0 --14:-7:0 --14:-6:0 --14:-5:0 --14:-4:0 --14:-3:0 --14:-2:0 --14:-1:0 --14:0:1 --14:1:-14 --14:2:105 --14:3:-560 --14:4:2380 --14:5:-8568 --14:6:27132 --14:7:-77520 --14:8:203490 --14:9:-497420 --14:10:1144066 --14:11:-2496144 --14:12:5200300 --14:13:-10400600 --14:14:20058300 --14:15:-37442160 - -# n = -13, k = n - 15 ... n + 15 - --13:-28:-17383860 --13:-27:9657700 --13:-26:-5200300 --13:-25:2704156 --13:-24:-1352078 --13:-23:646646 --13:-22:-293930 --13:-21:125970 --13:-20:-50388 --13:-19:18564 --13:-18:-6188 --13:-17:1820 --13:-16:-455 --13:-15:91 --13:-14:-13 --13:-13:1 --13:-12:0 --13:-11:0 --13:-10:0 --13:-9:0 --13:-8:0 --13:-7:0 --13:-6:0 --13:-5:0 --13:-4:0 --13:-3:0 --13:-2:0 --13:-1:0 --13:0:1 --13:1:-13 --13:2:91 --13:3:-455 --13:4:1820 --13:5:-6188 --13:6:18564 --13:7:-50388 --13:8:125970 --13:9:-293930 --13:10:646646 --13:11:-1352078 --13:12:2704156 --13:13:-5200300 --13:14:9657700 --13:15:-17383860 - -# n = -12, k = n - 15 ... n + 15 - --12:-27:-7726160 --12:-26:4457400 --12:-25:-2496144 --12:-24:1352078 --12:-23:-705432 --12:-22:352716 --12:-21:-167960 --12:-20:75582 --12:-19:-31824 --12:-18:12376 --12:-17:-4368 --12:-16:1365 --12:-15:-364 --12:-14:78 --12:-13:-12 --12:-12:1 --12:-11:0 --12:-10:0 --12:-9:0 --12:-8:0 --12:-7:0 --12:-6:0 --12:-5:0 --12:-4:0 --12:-3:0 --12:-2:0 --12:-1:0 --12:0:1 --12:1:-12 --12:2:78 --12:3:-364 --12:4:1365 --12:5:-4368 --12:6:12376 --12:7:-31824 --12:8:75582 --12:9:-167960 --12:10:352716 --12:11:-705432 --12:12:1352078 --12:13:-2496144 --12:14:4457400 --12:15:-7726160 - -# n = -11, k = n - 15 ... n + 15 - --11:-26:-3268760 --11:-25:1961256 --11:-24:-1144066 --11:-23:646646 --11:-22:-352716 --11:-21:184756 --11:-20:-92378 --11:-19:43758 --11:-18:-19448 --11:-17:8008 --11:-16:-3003 --11:-15:1001 --11:-14:-286 --11:-13:66 --11:-12:-11 --11:-11:1 --11:-10:0 --11:-9:0 --11:-8:0 --11:-7:0 --11:-6:0 --11:-5:0 --11:-4:0 --11:-3:0 --11:-2:0 --11:-1:0 --11:0:1 --11:1:-11 --11:2:66 --11:3:-286 --11:4:1001 --11:5:-3003 --11:6:8008 --11:7:-19448 --11:8:43758 --11:9:-92378 --11:10:184756 --11:11:-352716 --11:12:646646 --11:13:-1144066 --11:14:1961256 --11:15:-3268760 - -# n = -10, k = n - 15 ... n + 15 - --10:-25:-1307504 --10:-24:817190 --10:-23:-497420 --10:-22:293930 --10:-21:-167960 --10:-20:92378 --10:-19:-48620 --10:-18:24310 --10:-17:-11440 --10:-16:5005 --10:-15:-2002 --10:-14:715 --10:-13:-220 --10:-12:55 --10:-11:-10 --10:-10:1 --10:-9:0 --10:-8:0 --10:-7:0 --10:-6:0 --10:-5:0 --10:-4:0 --10:-3:0 --10:-2:0 --10:-1:0 --10:0:1 --10:1:-10 --10:2:55 --10:3:-220 --10:4:715 --10:5:-2002 --10:6:5005 --10:7:-11440 --10:8:24310 --10:9:-48620 --10:10:92378 --10:11:-167960 --10:12:293930 --10:13:-497420 --10:14:817190 --10:15:-1307504 - -# n = -9, k = n - 15 ... n + 15 - --9:-24:-490314 --9:-23:319770 --9:-22:-203490 --9:-21:125970 --9:-20:-75582 --9:-19:43758 --9:-18:-24310 --9:-17:12870 --9:-16:-6435 --9:-15:3003 --9:-14:-1287 --9:-13:495 --9:-12:-165 --9:-11:45 --9:-10:-9 --9:-9:1 --9:-8:0 --9:-7:0 --9:-6:0 --9:-5:0 --9:-4:0 --9:-3:0 --9:-2:0 --9:-1:0 --9:0:1 --9:1:-9 --9:2:45 --9:3:-165 --9:4:495 --9:5:-1287 --9:6:3003 --9:7:-6435 --9:8:12870 --9:9:-24310 --9:10:43758 --9:11:-75582 --9:12:125970 --9:13:-203490 --9:14:319770 --9:15:-490314 - -# n = -8, k = n - 15 ... n + 15 - --8:-23:-170544 --8:-22:116280 --8:-21:-77520 --8:-20:50388 --8:-19:-31824 --8:-18:19448 --8:-17:-11440 --8:-16:6435 --8:-15:-3432 --8:-14:1716 --8:-13:-792 --8:-12:330 --8:-11:-120 --8:-10:36 --8:-9:-8 --8:-8:1 --8:-7:0 --8:-6:0 --8:-5:0 --8:-4:0 --8:-3:0 --8:-2:0 --8:-1:0 --8:0:1 --8:1:-8 --8:2:36 --8:3:-120 --8:4:330 --8:5:-792 --8:6:1716 --8:7:-3432 --8:8:6435 --8:9:-11440 --8:10:19448 --8:11:-31824 --8:12:50388 --8:13:-77520 --8:14:116280 --8:15:-170544 - -# n = -7, k = n - 15 ... n + 15 - --7:-22:-54264 --7:-21:38760 --7:-20:-27132 --7:-19:18564 --7:-18:-12376 --7:-17:8008 --7:-16:-5005 --7:-15:3003 --7:-14:-1716 --7:-13:924 --7:-12:-462 --7:-11:210 --7:-10:-84 --7:-9:28 --7:-8:-7 --7:-7:1 --7:-6:0 --7:-5:0 --7:-4:0 --7:-3:0 --7:-2:0 --7:-1:0 --7:0:1 --7:1:-7 --7:2:28 --7:3:-84 --7:4:210 --7:5:-462 --7:6:924 --7:7:-1716 --7:8:3003 --7:9:-5005 --7:10:8008 --7:11:-12376 --7:12:18564 --7:13:-27132 --7:14:38760 --7:15:-54264 - -# n = -6, k = n - 15 ... n + 15 - --6:-21:-15504 --6:-20:11628 --6:-19:-8568 --6:-18:6188 --6:-17:-4368 --6:-16:3003 --6:-15:-2002 --6:-14:1287 --6:-13:-792 --6:-12:462 --6:-11:-252 --6:-10:126 --6:-9:-56 --6:-8:21 --6:-7:-6 --6:-6:1 --6:-5:0 --6:-4:0 --6:-3:0 --6:-2:0 --6:-1:0 --6:0:1 --6:1:-6 --6:2:21 --6:3:-56 --6:4:126 --6:5:-252 --6:6:462 --6:7:-792 --6:8:1287 --6:9:-2002 --6:10:3003 --6:11:-4368 --6:12:6188 --6:13:-8568 --6:14:11628 --6:15:-15504 - -# n = -5, k = n - 15 ... n + 15 - --5:-20:-3876 --5:-19:3060 --5:-18:-2380 --5:-17:1820 --5:-16:-1365 --5:-15:1001 --5:-14:-715 --5:-13:495 --5:-12:-330 --5:-11:210 --5:-10:-126 --5:-9:70 --5:-8:-35 --5:-7:15 --5:-6:-5 --5:-5:1 --5:-4:0 --5:-3:0 --5:-2:0 --5:-1:0 --5:0:1 --5:1:-5 --5:2:15 --5:3:-35 --5:4:70 --5:5:-126 --5:6:210 --5:7:-330 --5:8:495 --5:9:-715 --5:10:1001 --5:11:-1365 --5:12:1820 --5:13:-2380 --5:14:3060 --5:15:-3876 - -# n = -4, k = n - 15 ... n + 15 - --4:-19:-816 --4:-18:680 --4:-17:-560 --4:-16:455 --4:-15:-364 --4:-14:286 --4:-13:-220 --4:-12:165 --4:-11:-120 --4:-10:84 --4:-9:-56 --4:-8:35 --4:-7:-20 --4:-6:10 --4:-5:-4 --4:-4:1 --4:-3:0 --4:-2:0 --4:-1:0 --4:0:1 --4:1:-4 --4:2:10 --4:3:-20 --4:4:35 --4:5:-56 --4:6:84 --4:7:-120 --4:8:165 --4:9:-220 --4:10:286 --4:11:-364 --4:12:455 --4:13:-560 --4:14:680 --4:15:-816 - -# n = -3, k = n - 15 ... n + 15 - --3:-18:-136 --3:-17:120 --3:-16:-105 --3:-15:91 --3:-14:-78 --3:-13:66 --3:-12:-55 --3:-11:45 --3:-10:-36 --3:-9:28 --3:-8:-21 --3:-7:15 --3:-6:-10 --3:-5:6 --3:-4:-3 --3:-3:1 --3:-2:0 --3:-1:0 --3:0:1 --3:1:-3 --3:2:6 --3:3:-10 --3:4:15 --3:5:-21 --3:6:28 --3:7:-36 --3:8:45 --3:9:-55 --3:10:66 --3:11:-78 --3:12:91 --3:13:-105 --3:14:120 --3:15:-136 - -# n = -2, k = n - 15 ... n + 15 - --2:-17:-16 --2:-16:15 --2:-15:-14 --2:-14:13 --2:-13:-12 --2:-12:11 --2:-11:-10 --2:-10:9 --2:-9:-8 --2:-8:7 --2:-7:-6 --2:-6:5 --2:-5:-4 --2:-4:3 --2:-3:-2 --2:-2:1 --2:-1:0 --2:0:1 --2:1:-2 --2:2:3 --2:3:-4 --2:4:5 --2:5:-6 --2:6:7 --2:7:-8 --2:8:9 --2:9:-10 --2:10:11 --2:11:-12 --2:12:13 --2:13:-14 --2:14:15 --2:15:-16 - -# n = -1, k = n - 15 ... n + 15 - --1:-16:-1 --1:-15:1 --1:-14:-1 --1:-13:1 --1:-12:-1 --1:-11:1 --1:-10:-1 --1:-9:1 --1:-8:-1 --1:-7:1 --1:-6:-1 --1:-5:1 --1:-4:-1 --1:-3:1 --1:-2:-1 --1:-1:1 --1:0:1 --1:1:-1 --1:2:1 --1:3:-1 --1:4:1 --1:5:-1 --1:6:1 --1:7:-1 --1:8:1 --1:9:-1 --1:10:1 --1:11:-1 --1:12:1 --1:13:-1 --1:14:1 --1:15:-1 - -# n = 0, k = n - 15 ... n + 15 - -0:-15:0 -0:-14:0 -0:-13:0 -0:-12:0 -0:-11:0 -0:-10:0 -0:-9:0 -0:-8:0 -0:-7:0 -0:-6:0 -0:-5:0 -0:-4:0 -0:-3:0 -0:-2:0 -0:-1:0 -0:0:1 -0:1:0 -0:2:0 -0:3:0 -0:4:0 -0:5:0 -0:6:0 -0:7:0 -0:8:0 -0:9:0 -0:10:0 -0:11:0 -0:12:0 -0:13:0 -0:14:0 -0:15:0 - -# n = 1, k = n - 15 ... n + 15 - -1:-15:0 -1:-14:0 -1:-13:0 -1:-12:0 -1:-11:0 -1:-10:0 -1:-9:0 -1:-8:0 -1:-7:0 -1:-6:0 -1:-5:0 -1:-4:0 -1:-3:0 -1:-2:0 -1:-1:0 -1:0:1 -1:1:1 -1:2:0 -1:3:0 -1:4:0 -1:5:0 -1:6:0 -1:7:0 -1:8:0 -1:9:0 -1:10:0 -1:11:0 -1:12:0 -1:13:0 -1:14:0 -1:15:0 -1:16:0 - -# n = 2, k = n - 15 ... n + 15 - -2:-15:0 -2:-14:0 -2:-13:0 -2:-12:0 -2:-11:0 -2:-10:0 -2:-9:0 -2:-8:0 -2:-7:0 -2:-6:0 -2:-5:0 -2:-4:0 -2:-3:0 -2:-2:0 -2:-1:0 -2:0:1 -2:1:2 -2:2:1 -2:3:0 -2:4:0 -2:5:0 -2:6:0 -2:7:0 -2:8:0 -2:9:0 -2:10:0 -2:11:0 -2:12:0 -2:13:0 -2:14:0 -2:15:0 -2:16:0 -2:17:0 - -# n = 3, k = n - 15 ... n + 15 - -3:-15:0 -3:-14:0 -3:-13:0 -3:-12:0 -3:-11:0 -3:-10:0 -3:-9:0 -3:-8:0 -3:-7:0 -3:-6:0 -3:-5:0 -3:-4:0 -3:-3:0 -3:-2:0 -3:-1:0 -3:0:1 -3:1:3 -3:2:3 -3:3:1 -3:4:0 -3:5:0 -3:6:0 -3:7:0 -3:8:0 -3:9:0 -3:10:0 -3:11:0 -3:12:0 -3:13:0 -3:14:0 -3:15:0 -3:16:0 -3:17:0 -3:18:0 - -# n = 4, k = n - 15 ... n + 15 - -4:-15:0 -4:-14:0 -4:-13:0 -4:-12:0 -4:-11:0 -4:-10:0 -4:-9:0 -4:-8:0 -4:-7:0 -4:-6:0 -4:-5:0 -4:-4:0 -4:-3:0 -4:-2:0 -4:-1:0 -4:0:1 -4:1:4 -4:2:6 -4:3:4 -4:4:1 -4:5:0 -4:6:0 -4:7:0 -4:8:0 -4:9:0 -4:10:0 -4:11:0 -4:12:0 -4:13:0 -4:14:0 -4:15:0 -4:16:0 -4:17:0 -4:18:0 -4:19:0 - -# n = 5, k = n - 15 ... n + 15 - -5:-15:0 -5:-14:0 -5:-13:0 -5:-12:0 -5:-11:0 -5:-10:0 -5:-9:0 -5:-8:0 -5:-7:0 -5:-6:0 -5:-5:0 -5:-4:0 -5:-3:0 -5:-2:0 -5:-1:0 -5:0:1 -5:1:5 -5:2:10 -5:3:10 -5:4:5 -5:5:1 -5:6:0 -5:7:0 -5:8:0 -5:9:0 -5:10:0 -5:11:0 -5:12:0 -5:13:0 -5:14:0 -5:15:0 -5:16:0 -5:17:0 -5:18:0 -5:19:0 -5:20:0 - -# n = 6, k = n - 15 ... n + 15 - -6:-15:0 -6:-14:0 -6:-13:0 -6:-12:0 -6:-11:0 -6:-10:0 -6:-9:0 -6:-8:0 -6:-7:0 -6:-6:0 -6:-5:0 -6:-4:0 -6:-3:0 -6:-2:0 -6:-1:0 -6:0:1 -6:1:6 -6:2:15 -6:3:20 -6:4:15 -6:5:6 -6:6:1 -6:7:0 -6:8:0 -6:9:0 -6:10:0 -6:11:0 -6:12:0 -6:13:0 -6:14:0 -6:15:0 -6:16:0 -6:17:0 -6:18:0 -6:19:0 -6:20:0 -6:21:0 - -# n = 7, k = n - 15 ... n + 15 - -7:-15:0 -7:-14:0 -7:-13:0 -7:-12:0 -7:-11:0 -7:-10:0 -7:-9:0 -7:-8:0 -7:-7:0 -7:-6:0 -7:-5:0 -7:-4:0 -7:-3:0 -7:-2:0 -7:-1:0 -7:0:1 -7:1:7 -7:2:21 -7:3:35 -7:4:35 -7:5:21 -7:6:7 -7:7:1 -7:8:0 -7:9:0 -7:10:0 -7:11:0 -7:12:0 -7:13:0 -7:14:0 -7:15:0 -7:16:0 -7:17:0 -7:18:0 -7:19:0 -7:20:0 -7:21:0 -7:22:0 - -# n = 8, k = n - 15 ... n + 15 - -8:-15:0 -8:-14:0 -8:-13:0 -8:-12:0 -8:-11:0 -8:-10:0 -8:-9:0 -8:-8:0 -8:-7:0 -8:-6:0 -8:-5:0 -8:-4:0 -8:-3:0 -8:-2:0 -8:-1:0 -8:0:1 -8:1:8 -8:2:28 -8:3:56 -8:4:70 -8:5:56 -8:6:28 -8:7:8 -8:8:1 -8:9:0 -8:10:0 -8:11:0 -8:12:0 -8:13:0 -8:14:0 -8:15:0 -8:16:0 -8:17:0 -8:18:0 -8:19:0 -8:20:0 -8:21:0 -8:22:0 -8:23:0 - -# n = 9, k = n - 15 ... n + 15 - -9:-15:0 -9:-14:0 -9:-13:0 -9:-12:0 -9:-11:0 -9:-10:0 -9:-9:0 -9:-8:0 -9:-7:0 -9:-6:0 -9:-5:0 -9:-4:0 -9:-3:0 -9:-2:0 -9:-1:0 -9:0:1 -9:1:9 -9:2:36 -9:3:84 -9:4:126 -9:5:126 -9:6:84 -9:7:36 -9:8:9 -9:9:1 -9:10:0 -9:11:0 -9:12:0 -9:13:0 -9:14:0 -9:15:0 -9:16:0 -9:17:0 -9:18:0 -9:19:0 -9:20:0 -9:21:0 -9:22:0 -9:23:0 -9:24:0 - -# n = 10, k = n - 15 ... n + 15 - -10:-15:0 -10:-14:0 -10:-13:0 -10:-12:0 -10:-11:0 -10:-10:0 -10:-9:0 -10:-8:0 -10:-7:0 -10:-6:0 -10:-5:0 -10:-4:0 -10:-3:0 -10:-2:0 -10:-1:0 -10:0:1 -10:1:10 -10:2:45 -10:3:120 -10:4:210 -10:5:252 -10:6:210 -10:7:120 -10:8:45 -10:9:10 -10:10:1 -10:11:0 -10:12:0 -10:13:0 -10:14:0 -10:15:0 -10:16:0 -10:17:0 -10:18:0 -10:19:0 -10:20:0 -10:21:0 -10:22:0 -10:23:0 -10:24:0 -10:25:0 - -# n = 11, k = n - 15 ... n + 15 - -11:-15:0 -11:-14:0 -11:-13:0 -11:-12:0 -11:-11:0 -11:-10:0 -11:-9:0 -11:-8:0 -11:-7:0 -11:-6:0 -11:-5:0 -11:-4:0 -11:-3:0 -11:-2:0 -11:-1:0 -11:0:1 -11:1:11 -11:2:55 -11:3:165 -11:4:330 -11:5:462 -11:6:462 -11:7:330 -11:8:165 -11:9:55 -11:10:11 -11:11:1 -11:12:0 -11:13:0 -11:14:0 -11:15:0 -11:16:0 -11:17:0 -11:18:0 -11:19:0 -11:20:0 -11:21:0 -11:22:0 -11:23:0 -11:24:0 -11:25:0 -11:26:0 - -# n = 12, k = n - 15 ... n + 15 - -12:-15:0 -12:-14:0 -12:-13:0 -12:-12:0 -12:-11:0 -12:-10:0 -12:-9:0 -12:-8:0 -12:-7:0 -12:-6:0 -12:-5:0 -12:-4:0 -12:-3:0 -12:-2:0 -12:-1:0 -12:0:1 -12:1:12 -12:2:66 -12:3:220 -12:4:495 -12:5:792 -12:6:924 -12:7:792 -12:8:495 -12:9:220 -12:10:66 -12:11:12 -12:12:1 -12:13:0 -12:14:0 -12:15:0 -12:16:0 -12:17:0 -12:18:0 -12:19:0 -12:20:0 -12:21:0 -12:22:0 -12:23:0 -12:24:0 -12:25:0 -12:26:0 -12:27:0 - -# n = 13, k = n - 15 ... n + 15 - -13:-15:0 -13:-14:0 -13:-13:0 -13:-12:0 -13:-11:0 -13:-10:0 -13:-9:0 -13:-8:0 -13:-7:0 -13:-6:0 -13:-5:0 -13:-4:0 -13:-3:0 -13:-2:0 -13:-1:0 -13:0:1 -13:1:13 -13:2:78 -13:3:286 -13:4:715 -13:5:1287 -13:6:1716 -13:7:1716 -13:8:1287 -13:9:715 -13:10:286 -13:11:78 -13:12:13 -13:13:1 -13:14:0 -13:15:0 -13:16:0 -13:17:0 -13:18:0 -13:19:0 -13:20:0 -13:21:0 -13:22:0 -13:23:0 -13:24:0 -13:25:0 -13:26:0 -13:27:0 -13:28:0 - -# n = 14, k = n - 15 ... n + 15 - -14:-15:0 -14:-14:0 -14:-13:0 -14:-12:0 -14:-11:0 -14:-10:0 -14:-9:0 -14:-8:0 -14:-7:0 -14:-6:0 -14:-5:0 -14:-4:0 -14:-3:0 -14:-2:0 -14:-1:0 -14:0:1 -14:1:14 -14:2:91 -14:3:364 -14:4:1001 -14:5:2002 -14:6:3003 -14:7:3432 -14:8:3003 -14:9:2002 -14:10:1001 -14:11:364 -14:12:91 -14:13:14 -14:14:1 -14:15:0 -14:16:0 -14:17:0 -14:18:0 -14:19:0 -14:20:0 -14:21:0 -14:22:0 -14:23:0 -14:24:0 -14:25:0 -14:26:0 -14:27:0 -14:28:0 -14:29:0 - -# n = 15, k = n - 15 ... n + 15 - -15:-15:0 -15:-14:0 -15:-13:0 -15:-12:0 -15:-11:0 -15:-10:0 -15:-9:0 -15:-8:0 -15:-7:0 -15:-6:0 -15:-5:0 -15:-4:0 -15:-3:0 -15:-2:0 -15:-1:0 -15:0:1 -15:1:15 -15:2:105 -15:3:455 -15:4:1365 -15:5:3003 -15:6:5005 -15:7:6435 -15:8:6435 -15:9:5005 -15:10:3003 -15:11:1365 -15:12:455 -15:13:105 -15:14:15 -15:15:1 -15:16:0 -15:17:0 -15:18:0 -15:19:0 -15:20:0 -15:21:0 -15:22:0 -15:23:0 -15:24:0 -15:25:0 -15:26:0 -15:27:0 -15:28:0 -15:29:0 -15:30:0 diff --git a/cpan/Math-BigRat/t/const-mbr.t b/cpan/Math-BigRat/t/const-mbr.t deleted file mode 100644 index 672882d3be47..000000000000 --- a/cpan/Math-BigRat/t/const-mbr.t +++ /dev/null @@ -1,319 +0,0 @@ -# -*- mode: perl; -*- - -# Binary, octal, and hexadecimal floating point literals were introduced in -# v5.22.0. -# -# - It wasn't until v5.28.0 that binary, octal, and hexadecimal floating point -# literals were converted to the correct value on perls compiled with quadmath -# support. -# -# - It wasn't until v5.32.0 that binary and octal floating point literals worked -# correctly with constant overloading. Before v5.32.0, it seems like the -# second character is always silently converted to an "x", so, e.g., "0b1.1p8" -# is passed to the overload::constant subroutine as "0x1.1p8", and "01.1p+8" -# is passed as "0x.1p+8". -# -# - Octal floating point literals using the "0o" prefix were introduced in -# v5.34.0. - -# Note that all numeric literals that should not be overloaded must be quoted. - -use strict; -use warnings; - -use Test::More tests => "171"; - -use Math::BigRat ":constant"; - -my $class = "Math::BigRat"; -my $x; - -################################################################################ -# The following tests should be identical for Math::BigInt, Math::BigFloat and -# Math::BigRat. - -# These are handled by "binary". - -$x = 0xff; -is($x, "255", "hexadecimal integer literal 0xff"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Hexadecimal literals using the "0X" prefix require v5.14.0. - skip "perl v5.14.0 required for hexadecimal integer literals" - . " with '0X' prefix", "2" if $] < "5.014"; - - $x = eval "0XFF"; - is($x, "255", "hexadecimal integer literal 0XFF"); - is(ref($x), $class, "value is a $class"); -} - -$x = 0377; -is($x, "255", "octal integer literal 0377"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Octal literals using the "0o" prefix requires v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "4" if $] < "5.034"; - - for my $str (qw/ 0o377 0O377 /) { - $x = eval $str; - is($x, "255", "octal integer literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -$x = 0b11111111; -is($x, "255", "binary integer literal 0b11111111"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Binary literals using the "0B" prefix require v5.14.0. - skip "perl v5.14.0 required for binary integer literals" - . " with '0B' prefix", "2" if $] < "5.014"; - - $x = eval "0B11111111"; - is($x, "255", "binary integer literal 0B11111111"); - is(ref($x), $class, "value is a $class"); -} - -# These are handled by "float". - -$x = 999999999999999999999999999999999999999999999999999999999999999999999999; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999", - "decimal integer literal " . ("9" x 72)); -is(ref($x), $class, "value is a $class"); - -$x = 1e72 - 1; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999", - "literal 1e72 - 1"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "float". - -SKIP: { - # Hexadecimal floating point literals require v5.28.0. - skip "perl v5.28.0 required for hexadecimal floating point literals", - "6" * "2" + "2" * "2" if $] < "5.028"; - - for my $str (qw/ 0x1.3ap+8 0X1.3AP+8 - 0x1.3ap8 0X1.3AP8 - 0x13a0p-4 0X13A0P-4 /) - { - $x = eval $str; - is($x, "314", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0x0.0p+8 0X0.0P+8 /) - { - $x = eval $str; - is($x, "0", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0o" prefix require v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "6" * "2" + "6" * "2" if $] < "5.034"; - - for my $str (qw/ 0o1.164p+8 0O1.164P+8 - 0o1.164p8 0O1.164P8 - 0o11640p-4 0O11640P-4 /) - { - $x = eval $str; - is($x, "314", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0o0.0p+8 0O0.0P+8 - 0o0.0p8 0O0.0P8 - 0o0.0p-8 0O0.0P-8 /) - { - $x = eval $str; - is($x, "0", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0" prefix require v5.32.0. - skip "perl v5.32.0 required for octal floating point literals", - "6" * "2" + "6" * "2" if $] < "5.032"; - - for my $str (qw/ 01.164p+8 01.164P+8 - 01.164p8 01.164P8 - 011640p-4 011640P-4 /) - { - $x = eval $str; - is($x, "314", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 00.0p+8 00.0P+8 - 00.0p8 00.0P8 - 00.0p-8 00.0P-8 /) - { - $x = eval $str; - is($x, "0", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Binary floating point literals require v5.32.0. - skip "perl v5.32.0 required for binary floating point literals", - "6" * "2" + "6" * "2" if $] < "5.032"; - - for my $str (qw/ 0b1.0011101p+8 0B1.0011101P+8 - 0b1.0011101p8 0B1.0011101P8 - 0b10011101000p-2 0B10011101000P-2 /) - { - $x = eval $str; - is($x, "314", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0b0p+8 0B0P+8 - 0b0p8 0B0P8 - 0b0p-8 0B0P-8 - /) - { - $x = eval $str; - is($x, "0", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -# These are handled by "integer". - -$x = 314; -is($x, "314", "integer literal 314"); -is(ref($x), $class, "value is a $class"); - -$x = 0; -is($x, "0", "integer literal 0"); -is(ref($x), $class, "value is a $class"); - -$x = 2 ** 255; -is($x, - "578960446186580977117854925043439539266" - . "34992332820282019728792003956564819968", - "2 ** 255"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "binary". - -{ - no warnings "portable"; # protect against "non-portable" warnings - - # hexadecimal constant - $x = 0x123456789012345678901234567890; - is($x, - "94522879687365475552814062743484560", - "hexadecimal constant 0x123456789012345678901234567890"); - is(ref($x), $class, "value is a $class"); - - # octal constant - $x = 012345676543210123456765432101234567654321; - is($x, - "1736132869400711976876385488263403729", - "octal constant 012345676543210123456765432101234567654321"); - is(ref($x), $class, "value is a $class"); - - # binary constant - $x = 0b01010100011001010110110001110011010010010110000101101101; - is($x, - "23755414508757357", - "binary constant 0b0101010001100101011011000111" - . "0011010010010110000101101101"); - is(ref($x), $class, "value is a $class"); -} - -################################################################################ -# The following tests are unique to $class. - -# These are handled by "float". - -$x = 0.999999999999999999999999999999999999999999999999999999999999999999999999; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999" . - "/1000000000000000000000000000000000000000000000000000000000000000000000000", - "decimal floating point literal 0." . ("9" x 72)); -is(ref($x), $class, "value is a $class"); - -$x = 1e72 - 0.1; -is($x, - "9999999999999999999999999999999999999999999999999999999999999999999999999" - . "/10", - "literal 1e72 - 0.1"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "float". - -SKIP: { - # Hexadecimal floating point literals require v5.28.0. - skip "perl v5.28.0 required for hexadecimal floating point literals", - "6" * "2" if $] < "5.028"; - - for my $str (qw/ 0x1.92p+1 0X1.92P+1 - 0x1.92p1 0X1.92P1 - 0x19.2p-3 0X19.2P-3 /) - { - $x = eval $str; - is($x, "201/64", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0o" prefix require v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "6" * "2" if $] < "5.034"; - - for my $str (qw/ 0o1.444p+1 0O1.444P+1 - 0o1.444p1 0O1.444P1 - 0o14.44p-2 0O14.44P-2 /) - { - $x = eval $str; - is($x, "201/64", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0" prefix require v5.32.0. - skip "perl v5.32.0 required for octal floating point literals", - "6" * "2" if $] < "5.032"; - - for my $str (qw/ 01.444p+1 01.444P+1 - 01.444p1 01.444P1 - 014.44p-2 014.44P-2 /) - { - $x = eval $str; - is($x, "201/64", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Binary floating point literals require v5.32.0. - skip "perl v5.32.0 required for binary floating point literals", - "6" * "2" if $] < "5.032"; - - for my $str (qw/ 0b1.1001001p+1 0B1.1001001P+1 - 0b1.1001001p1 0B1.1001001P1 - 0b110.01001p-1 0B110.01001P-1 /) - { - $x = eval $str; - is($x, "201/64", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -is(1.0 / 3.0, "1/3", - "1.0 / 3.0 = 1/3"); diff --git a/cpan/Math-BigRat/t/dparts-mbr.t b/cpan/Math-BigRat/t/dparts-mbr.t deleted file mode 100644 index 454bf59a0fad..000000000000 --- a/cpan/Math-BigRat/t/dparts-mbr.t +++ /dev/null @@ -1,67 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 17; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($x_str, $int_str, $frc_str) = split /:/; - my $test; - - $test = qq|\$x = $class -> new("$x_str");| - . qq| (\$i, \$f) = \$x -> dparts();|; - - subtest $test => sub { - plan tests => 5; - - my $x = $class -> new($x_str); - my ($int_got, $frc_got) = $x -> dparts(); - - is(ref($int_got), $class, "class of integer part"); - is(ref($frc_got), $class, "class of fraction part"); - - is($int_got, $int_str, "value of integer part"); - is($frc_got, $frc_str, "value of fraction part"); - is($x, $x_str, "input is unmodified"); - }; - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$i = \$x -> dparts();|; - - subtest $test => sub { - plan tests => 3, - - my $x = $class -> new($x_str); - my $int_got = $x -> dparts(); - - isa_ok($int_got, $class); - - is($int_got, $int_str, "value of integer part"); - is($x, $x_str, "input is unmodified"); - }; -} - -__DATA__ - -NaN:NaN:NaN - -inf:inf:0 --inf:-inf:0 - --9/4:-2:-1/4 --1:-1:0 -0:0:0 -1:1:0 -9/4:2:1/4 diff --git a/cpan/Math-BigRat/t/fparts-mbr.t b/cpan/Math-BigRat/t/fparts-mbr.t deleted file mode 100644 index 8239760791fc..000000000000 --- a/cpan/Math-BigRat/t/fparts-mbr.t +++ /dev/null @@ -1,97 +0,0 @@ -# -*- mode: perl; -*- - -# test fparts(), numerator(), denominator() - -use strict; -use warnings; - -use Test::More tests => 43; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($x_str, $n_str, $d_str) = split /:/; - my $test; - - # test fparts() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| (\$n, \$d) = \$x -> fparts();|; - - subtest $test => sub { - plan tests => 5; - - my $x = $class -> new($x_str); - my ($n, $d) = $x -> fparts(); - - is(ref($n), $class, "class of numerator"); - is(ref($d), $class, "class of denominator"); - - is($n, $n_str, "value of numerator"); - is($d, $d_str, "value of denominator"); - is($x, $x_str, "input is unmodified"); - }; - - # test numerator() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$n = \$x -> numerator();|; - - subtest $test => sub { - plan tests => 3; - - my $x = $class -> new($x_str); - my $n = $x -> numerator(); - - is(ref($n), "Math::BigInt", "class of numerator"); - - is($n, $n_str, "value of numerator"); - is($x, $x_str, "input is unmodified"); - }; - - # test denominator() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$d = \$x -> denominator();|; - - subtest $test => sub { - plan tests => 3; - - my $x = $class -> new($x_str); - my $d = $x -> denominator(); - - is(ref($d), "Math::BigInt", "class of denominator"); - - is($d, $d_str, "value of denominator"); - is($x, $x_str, "input is unmodified"); - }; -} - -__DATA__ - -NaN:NaN:NaN - -inf:inf:1 --inf:-inf:1 - --30:-30:1 --3:-3:1 --1:-1:1 -0:0:1 -1:1:1 -3:3:1 -30:30:1 - --31400:-31400:1 --157/50:-157:50 -157/50:157:50 -31400:31400:1 diff --git a/cpan/Math-BigRat/t/new-mbr.t b/cpan/Math-BigRat/t/new-mbr.t deleted file mode 100644 index 24da7a835676..000000000000 --- a/cpan/Math-BigRat/t/new-mbr.t +++ /dev/null @@ -1,68 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 8; - -my $class; - -BEGIN { $class = 'Math::BigRat'; } -BEGIN { use_ok($class); } - -use Scalar::Util qw< refaddr >; - -# CPAN RT #132712. - -my $q1 = $class -> new("-1/2"); -my ($n, $d) = $q1 -> parts(); - -my $n_orig = $n -> copy(); -my $d_orig = $d -> copy(); -my $q2 = $class -> new($n, $d); - -cmp_ok($n, "==", $n_orig, - "The value of the numerator hasn't changed"); -cmp_ok($d, "==", $d_orig, - "The value of the denominator hasn't changed"); - -isnt(refaddr($n), refaddr($n_orig), - "The addresses of the numerators have changed"); -isnt(refaddr($d), refaddr($d_orig), - "The addresses of the denominators have changed"); - -# new() - -{ - my $x = $class -> new(); - subtest qq|\$x = $class -> new();|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "0", 'output arg has the right value'); - }; -} - -# new("") - -{ - my $x = $class -> new(""); - subtest qq|\$x = $class -> new("");|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "NaN", 'output arg has the right value'); - }; -} - -# new(undef) - -{ - my $x = $class -> new(undef); - subtest qq|\$x = $class -> new(undef);|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "0", 'output arg has the right value'); - }; -} diff --git a/cpan/Math-BigRat/t/requirer.t b/cpan/Math-BigRat/t/requirer.t deleted file mode 100644 index 4e2fadb9696c..000000000000 --- a/cpan/Math-BigRat/t/requirer.t +++ /dev/null @@ -1,18 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring BigRat works - -use strict; -use warnings; - -use Test::More tests => 1; - -my ($x); - -require Math::BigRat; -$x = Math::BigRat->new(1); -++$x; - -is($x, 2, '$x got successfully modified'); - -# all tests done diff --git a/cpan/Math-BigRat/t/trap.t b/cpan/Math-BigRat/t/trap.t deleted file mode 100644 index a61abb9b45cd..000000000000 --- a/cpan/Math-BigRat/t/trap.t +++ /dev/null @@ -1,105 +0,0 @@ -# -*- mode: perl; -*- - -# test that config( trap_nan => 1, trap_inf => 1) really works/dies - -use strict; -use warnings; - -use Test::More tests => 29; - -use Math::BigRat; - -my $mbr = 'Math::BigRat'; -my $x; - -foreach my $class ($mbr) { - - # can do? - can_ok($class, 'config'); - - ########################################################################### - # Default values. - ########################################################################### - - # defaults are okay? - is($class->config("trap_nan"), 0, qq|$class->config("trap_nan")|); - is($class->config("trap_inf"), 0, qq|$class->config("trap_inf")|); - - ########################################################################### - # Trap NaN. - ########################################################################### - - # can set? - $class->config( trap_nan => 1 ); - is($class->config("trap_nan"), 1, q|$class->config("trap_nan")|); - - # can reset? - $class->config( trap_nan => 0 ); - is($class->config("trap_nan"), 0, qq|$class->config("trap_nan")|); - - # can set via hash ref? - $class->config( { trap_nan => 1 } ); - is($class->config("trap_nan"), 1, q|$class->config("trap_nan")|); - - # also test that new() still works normally - eval { $x = $class->new("42"); $x->bnan(); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("42"); \$x->bnan();|); - # after new() never modified - is($x, 42, qq|\$x = $class->new("42"); \$x->bnan();|); - - # 0/0 => NaN - eval { $x = $class->new("0"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("0"); \$x->bdiv(0);|); - # after new() never modified - is($x, 0, qq|\$x = $class->new("0"); \$x->bdiv(0);|); - - ########################################################################### - # Trap inf. - ########################################################################### - - # can set? - $class->config( trap_inf => 1 ); - is($class->config("trap_inf"), 1, qq|$class->config("trap_inf")|); - - eval { $x = $class->new("4711"); $x->binf(); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("4711"); \$x->binf();|); - # after new() never modified - is($x, 4711, qq|\$x = $class->new("4711"); \$x->binf();|); - - # +$x/0 => +inf - eval { $x = $class->new("4711"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x =\$class->new("4711"); \$x->bdiv(0);|); - # after new() never modified - is($x, 4711, qq|\$x =\$class->new("4711"); \$x->bdiv(0);|); - - # -$x/0 => -inf - eval { $x = $class->new("-0815"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("-0815"); \$x->bdiv(0);|); - # after new() never modified - is($x, -815, qq|\$x = $class->new("-0815"); \$x->bdiv(0);|); -} - -############################################################################## -# BigRat - -Math::BigRat->config(trap_nan => 1, - trap_inf => 1); - -for my $trap (qw/ 0.1a +inf inf -inf /) { - my $x = Math::BigRat->new('7/4'); - - note(""); # this is just for some space in the output - - # In each of the cases below, $x is not modified, because the code dies. - - eval { $x = $mbr->new("$trap"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap");|); - - eval { $x = $mbr->new("$trap"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap");|); - - eval { $x = $mbr->new("$trap/7"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap/7");|); -} - -# all tests done diff --git a/t/porting/known_pod_issues.dat b/t/porting/known_pod_issues.dat index 2e6d8521e739..b76304165227 100644 --- a/t/porting/known_pod_issues.dat +++ b/t/porting/known_pod_issues.dat @@ -20,13 +20,13 @@ AnyEvent Apache::DProf Apache::MP3 Apache::SmallProf +App::find2perl Archive::Extract Array::Base arybase atan2(3) atof(3) atoi(3) -App::find2perl Attribute::Constant autobox B::Debug