Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package perl-Math-BigInt for openSUSE:Factory checked in at 2022-04-25 23:35:31 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Math-BigInt (Old) and /work/SRC/openSUSE:Factory/.perl-Math-BigInt.new.1538 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Math-BigInt" Mon Apr 25 23:35:31 2022 rev:40 rq:972542 version:1.999830 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Math-BigInt/perl-Math-BigInt.changes 2022-01-17 22:35:04.650284719 +0100 +++ /work/SRC/openSUSE:Factory/.perl-Math-BigInt.new.1538/perl-Math-BigInt.changes 2022-04-25 23:35:42.814432111 +0200 @@ -1,0 +2,11 @@ +Wed Apr 13 03:07:41 UTC 2022 - Tina M??ller <timueller+p...@suse.de> + +- updated to 1.999830 + see /usr/share/doc/packages/perl-Math-BigInt/CHANGES + + 1.999830 2022-04-11 + + * Improve upgrading and downgrading. This work is not complete. Some methods + still don't downgrade when they should. + +------------------------------------------------------------------- Old: ---- Math-BigInt-1.999829.tar.gz New: ---- Math-BigInt-1.999830.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Math-BigInt.spec ++++++ --- /var/tmp/diff_new_pack.QE2Aam/_old 2022-04-25 23:35:43.290432777 +0200 +++ /var/tmp/diff_new_pack.QE2Aam/_new 2022-04-25 23:35:43.294432783 +0200 @@ -18,10 +18,10 @@ %define cpan_name Math-BigInt Name: perl-Math-BigInt -Version: 1.999829 +Version: 1.999830 Release: 0 -Summary: Arbitrary size integer/float math package License: Artistic-1.0 OR GPL-1.0-or-later +Summary: Arbitrary size integer math package URL: https://metacpan.org/release/%{cpan_name} Source0: https://cpan.metacpan.org/authors/id/P/PJ/PJACKLAM/%{cpan_name}-%{version}.tar.gz Source1: cpanspec.yml ++++++ Math-BigInt-1.999829.tar.gz -> Math-BigInt-1.999830.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/CHANGES new/Math-BigInt-1.999830/CHANGES --- old/Math-BigInt-1.999829/CHANGES 2021-12-30 20:11:37.000000000 +0100 +++ new/Math-BigInt-1.999830/CHANGES 2022-04-11 08:19:14.000000000 +0200 @@ -1,3 +1,8 @@ +1.999830 2022-04-11 + + * Improve upgrading and downgrading. This work is not complete. Some methods + still don't downgrade when they should. + 1.999829 2021-12-29 * Improve methods div_scale() and round_mode() so they work better with diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/META.json new/Math-BigInt-1.999830/META.json --- old/Math-BigInt-1.999829/META.json 2021-12-31 07:18:14.000000000 +0100 +++ new/Math-BigInt-1.999830/META.json 2022-04-11 19:41:24.000000000 +0200 @@ -4,7 +4,7 @@ "Peter John Acklam <pjack...@gmail.com>" ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", + "generated_by" : "ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -50,6 +50,6 @@ "web" : "https://github.com/pjacklam/p5-Math-BigInt" } }, - "version" : "1.999829", + "version" : "1.999830", "x_serialization_backend" : "JSON::PP version 4.04" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/META.yml new/Math-BigInt-1.999830/META.yml --- old/Math-BigInt-1.999829/META.yml 2021-12-31 07:18:11.000000000 +0100 +++ new/Math-BigInt-1.999830/META.yml 2022-04-11 19:41:20.000000000 +0200 @@ -7,7 +7,7 @@ configure_requires: ExtUtils::MakeMaker: '6.58' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' +generated_by: 'ExtUtils::MakeMaker version 7.64, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -24,5 +24,5 @@ perl: '5.006001' resources: repository: https://github.com/pjacklam/p5-Math-BigInt.git -version: '1.999829' +version: '1.999830' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/SIGNATURE new/Math-BigInt-1.999830/SIGNATURE --- old/Math-BigInt-1.999829/SIGNATURE 2021-12-31 07:22:11.000000000 +0100 +++ new/Math-BigInt-1.999830/SIGNATURE 2022-04-11 19:41:37.000000000 +0200 @@ -15,15 +15,15 @@ Hash: RIPEMD160 SHA256 961f8c23b6fc94cb9766265257dd548b190087df0c71dfd7d994bc649af5f002 BUGS -SHA256 fc2051a38c658300221d137f958f03b476a9231e7b1261c927da7d88dd97abab CHANGES +SHA256 f27269756b7097265fb31f22caa2f8b96527d4e96d9d506132e93f10657ddff1 CHANGES SHA256 7d84c6e69ee6c3ab6301314d2fa4bc233f24bd36a4a546b2cfd05a078bda98b7 CREDITS SHA256 fd8f78318c23adef95971cc01ee0e79d68f52f60b761ba28129c8509fff46954 GOALS SHA256 28e80ee628ff111dd34a2a26af921693c9c823caadab30c848e4c4f4fc00830f HISTORY SHA256 b857edab549ac6893e2df5e1ec768ee46b62bcf1607a55e876f4d23f079eacce LICENSE SHA256 8ad41a4a11bfa5a79a24f42fdd2d034119f68b8a45994f430886213293a38549 MANIFEST SHA256 6cbc650165422bed661f292abb91ffaefa416830203a2aa8c790114ce6535cde MANIFEST.SKIP -SHA256 155a2bf7721d82cc136010d4ac7f1d3090dc349c81848b1071afbda66cab788a META.json -SHA256 ba54b6aaa68239592e1369979840f97be610b2246ae7de87319050cacbe7ed8c META.yml +SHA256 678115f83839213ec5fcc0e57006a6386bf5b1ffa8b6d22083f22e832774e7bc META.json +SHA256 b2d8fed4d7a1a24cf258599b52e4e26993f90be7e40f0c2da97a7663465f0552 META.yml SHA256 053b2511fa5ac8e6141b5596d6777220ef257a5ddfda3f3ff7325907757660a7 Makefile.PL SHA256 99f7f7df45a00c9f19ad38edec8c5dad5f5977c2b1a14ac3bb491ac193db1f7d NEW SHA256 2aadb8383836311d8b47a34b7eb1c68043ccd5b90bfc2d9c57016b33579d2385 README @@ -32,10 +32,10 @@ SHA256 77a80748e329a042faaa91eb0b44a493dfdfd726fec854a1a376c8404324b485 examples/1000.txt SHA256 702e323f59be58db758a3fa70ffe5fb80d392043bb855b0f172dd748809435df examples/bigprimes.pl SHA256 81a3ff3476038ec839c12a2b3548898055112bebc81fbf3513ee5efd6adfd0bd examples/prime.pl -SHA256 0a8b0bd9ed54b5e1e487c809e1acdea4ed680078c861f924cb8db8d7e7d628a5 lib/Math/BigFloat.pm -SHA256 bec3bcae7574ba141642227bcb7c1d37e090ef78ef8287eb54fff22f10345755 lib/Math/BigInt.pm -SHA256 ac5c5b684286e812fd6ac7b9b27b3df399921f432680b69ced8e2182fba21952 lib/Math/BigInt/Calc.pm -SHA256 ac22d1cbe00be0d8e5a32b639f62815d4496f44a1547149cca4363b09533ee85 lib/Math/BigInt/Lib.pm +SHA256 04a85f05f9c10f147a74c2a422985f7d4e983748a8ffd368f3a6f8e936023b57 lib/Math/BigFloat.pm +SHA256 f51b2c418456059bf622f8052e444cbf78f97e51450d73c9afb693d4d13de18e lib/Math/BigInt.pm +SHA256 69905767fc7fd1d3d053666ed9c0fe352659a9e3b407bf44bf80d88b85d608ab lib/Math/BigInt/Calc.pm +SHA256 ee4e0e1729abd17f0ae413b577f4418cad99bbd00712efe4703cfcb51ab21c55 lib/Math/BigInt/Lib.pm SHA256 f855e68d0f171debf8369ead8b36d004188f1c9069287a0d3c67a87f9afb1312 t/00sig.t SHA256 64c07f96b6a1d6adb075f40bf2dc496fd7951b653458bd9f826e4f76f8e5423d t/01load.t SHA256 a756e0bc9a221303e562d0f25969965962e6121605ee9bb0ee3cb54e69dd2222 t/Math/BigFloat/Subclass.pm @@ -92,7 +92,7 @@ SHA256 f07e3567088a090d21831714a0ecb3a6f697eb470d3125690a89e6d515e845a7 t/config.t SHA256 2ae8168531ed6415bdb20ec7aea33e77fb27f5b3236800e7fb0f139f400bc46a t/const-mbf.t SHA256 fe3ebc915d56ac4bbb3dbbdc91a9b25d56dbfcdd4da06c1aa44473a036d6e5f6 t/const-mbi.t -SHA256 edc69ab08976345088b5ce485ecc6cee0df5ae6c62748d80fc25f85d979e7c32 t/downgrade.t +SHA256 264117e304286b0752651e8964ceac739763f2bc0a5a7d509898112bd69ec70b t/downgrade.t SHA256 3b4f29c10335315aa9a7f43b496c32313ddd535b439f0e02000502077a964e5e t/dparts-mbf.t SHA256 20885f8ff653f1b7f03960ef1c2a83c227e4b045bb6977716da88f58753046d0 t/dparts-mbi.t SHA256 1214cb07c16402a1800db390f280a868765f1d6378282f6fd680d205bd0b47df t/eparts-mbf.t @@ -145,7 +145,7 @@ SHA256 a6c426fbe3be51614bba597884ccb3313e8896491f38c0443d8fa89b62b67d67 t/to_ieee754-mbf.t SHA256 733212fb1e51087fbbd66327659d4b4495f1464b3c19fd5069ab5cfdbcf5cec1 t/trap.t SHA256 c3c25192c24ce16d99ce65e7f540aeb95d48e25e8e6de7800ccbc3a26ae8e301 t/upgrade.inc -SHA256 4b38e59dc5af4860466b7897429b239111c8547a46a993ea860b86868283f9fa t/upgrade.t +SHA256 98af14554fc72403105b8fa4d21040c052bb33edc2cf3bb5acc0e8b34e590b3d t/upgrade.t SHA256 9ac713f4e86b7d682608372d672a1d078320b605fd704dfbecd3eda0eb9403e7 t/upgrade2.t SHA256 01b543fd9de9aacb54d5d4c64479a064e9c5e3050f9f79b88c0d8d5d2d858f4a t/upgradef.t SHA256 abb78d9e1b5f3bbb798f28050130d1fe03bfe61e6a8cb2110ea12795a1d5a850 t/use.t @@ -282,7 +282,7 @@ SHA256 594dcd1659befa019adbd521d4c8c60fc9f1446688b011780655272e6a56b61a xt/release/cpan-changes.t SHA256 befb07cbace153e844bd1aa24309e8136f0265cc97708bfb2f5f427964f7a88d xt/release/dist-manifest.t SHA256 dfba9c5f1e2b047a07c92747e523aceeab0d692a1bf655c2658386e45d9b4311 xt/release/distmeta.t -SHA256 9ce5216bb53107eaa7572564e87d15ac7749233b9c58a482de02cdf603ed2409 xt/release/git.t +SHA256 2f6418e76023a02d013902d68fb5d7a957bb4ba09b6150b05a4baf2efcd73386 xt/release/git.t SHA256 ab76d17849b85e317470c4307f01cc9f8c4e0bbc78556d61b4fd572f16eca31c xt/release/kwalitee.t SHA256 c6f4a981a4c1990e5f524646375b7b219c29cba04869438e5463c096c808bf09 xt/release/minimum-version.t SHA256 0d68719572b113c9a2f017b87c31ee934dfd016859c67772e50fddaab904eb07 xt/release/pod-coverage.t @@ -294,11 +294,11 @@ SHA256 7aa223732dec88d581e015ac171308b256a9d061ea3c832ad4f7048266226e97 xt/release/whitespaces.t -----BEGIN PGP SIGNATURE----- -iQEcBAEBAwAGBQJhzqCpAAoJEGcmPl2fr166CdQH/iYh739CuyZ1HoQktEL1h4Gh -JhiyAhhagMlEEBc2dn5ZHbBb5bQCQg8fEDKlcAnw4f9c9eunWA9I1W1hePjWRBkV -uysRXbCc27W+og+hz272CnUU3Zy0VfNoeYq7+fsPmwI3BJycLZetzlpl+FVAv73B -pmMA0Yj7jmrsiMx0XoSZKe6iilu0xbbXDKA/LYYfdOEvqrelrdn5VVMajb5XVZ8z -VhzhzQnerF1vIwR1cYuCZkDg0SWZBAJJ9mwQxXKjAFtlQkKxEkk3NTN6rDWkw+/k -r+MTDpv15w1hT7+zCmIaOMZkb6ZcW3DLWIb1MdZhPwFSDD9e+Eiy0TzGTUvaRI0= -=db4E +iQEcBAEBAwAGBQJiVGhIAAoJEGcmPl2fr166ngsH/jL0YJIr6l4qVBHCDq85b1YH +rAfKrq92lBLprJi416d+HSPVs0movDdFXXk9yo54ReDOqcLzztrekAmJtr7gUgg1 +hnEO9VFcLRCeykxLOWv4SP5NhiviUL2Y+8nBzpFX5MIeUdlH970d5YvJxifvVuMz +gPl0javjfaiZll85xD6T+9/VE2Ju7e3Iakc37XBBD/kW9zP92cfVAAm5Nar9hn43 +7MkViM9FS5TXzEE5x3nYZPvNEZ726gJDi4DYXdoPTFoz201Zy2UrXGodqKc9jvom +GDWwiAMtDjf2+BUx7I99+vUe+gsTAThtkWsT4tnjLSccpjZ1XCqMKfZACVMVH7A= +=8r1O -----END PGP SIGNATURE----- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/lib/Math/BigFloat.pm new/Math-BigInt-1.999830/lib/Math/BigFloat.pm --- old/Math-BigInt-1.999829/lib/Math/BigFloat.pm 2021-12-29 19:28:07.000000000 +0100 +++ new/Math-BigInt-1.999830/lib/Math/BigFloat.pm 2022-04-11 17:25:03.000000000 +0200 @@ -20,7 +20,8 @@ use Scalar::Util qw< blessed >; use Math::BigInt qw< >; -our $VERSION = '1.999829'; +our $VERSION = '1.999830'; +$VERSION =~ tr/_//d; require Exporter; our @ISA = qw/Math::BigInt/; @@ -426,11 +427,10 @@ } } - # Handle Infs. if ($wanted =~ /^\s*([+-]?)inf(inity)?\s*\z/i) { - return $downgrade->new($wanted) if $downgrade; + return $downgrade->new($wanted) if defined $downgrade; my $sgn = $1 || '+'; $self = $class -> binf($sgn); $self->round(@r) unless @r >= 2 && !defined($r[0]) && !defined($r[1]); @@ -440,7 +440,7 @@ # Handle explicit NaNs (not the ones returned due to invalid input). if ($wanted =~ /^\s*([+-]?)nan\s*\z/i) { - return $downgrade->new($wanted) if $downgrade; + return $downgrade->new($wanted) if defined $downgrade; $self = $class -> bnan(); $self->round(@r) unless @r >= 2 && !defined $r[0] && !defined $r[1]; return $self; @@ -457,7 +457,7 @@ $ /x) { - return $downgrade->new($1 . $2) if $downgrade; + return $downgrade->new($1 . $2) if defined $downgrade; $self->{sign} = $1 || '+'; $self->{_m} = $LIB -> _new($2); $self->{_es} = '+'; @@ -513,7 +513,6 @@ # The value is an integer iff the exponent is non-negative. if ($parts[2] eq '+' && $downgrade) { - #return $downgrade->new($str, @r); return $downgrade->new($wanted, @r); } @@ -548,9 +547,8 @@ # The value is an integer iff the exponent is non-negative. - if ($parts[2] eq '+' && $downgrade) { - #$str = $parts[0] . $LIB -> _lsft($parts[1], $parts[3], 10); - return $downgrade->new($str, @r); + if ($parts[2] eq '+') { + return $downgrade->new($str, @r) if defined $downgrade; } ($self->{sign}, $self->{_m}, $self->{_es}, $self->{_e}) = @parts; @@ -581,8 +579,7 @@ # The value is an integer iff the exponent is non-negative. - if ($parts[2] eq '+' && $downgrade) { - #$str = $parts[0] . $LIB -> _lsft($parts[1], $parts[3], 10); + if ($parts[2] eq '+' && defined $downgrade) { return $downgrade -> from_hex($str, @r); } @@ -614,9 +611,8 @@ # The value is an integer iff the exponent is non-negative. - if ($parts[2] eq '+' && $downgrade) { - #$str = $parts[0] . $LIB -> _lsft($parts[1], $parts[3], 10); - return $downgrade -> from_oct($str, @r); + if ($parts[2] eq '+') { + return $downgrade -> from_oct($str, @r) if defined $downgrade; } ($self->{sign}, $self->{_m}, $self->{_es}, $self->{_e}) = @parts; @@ -647,9 +643,8 @@ # The value is an integer iff the exponent is non-negative. - if ($parts[2] eq '+' && $downgrade) { - #$str = $parts[0] . $LIB -> _lsft($parts[1], $parts[3], 10); - return $downgrade -> from_bin($str, @r); + if ($parts[2] eq '+') { + return $downgrade -> from_bin($str, @r) if defined $downgrade; } ($self->{sign}, $self->{_m}, $self->{_es}, $self->{_e}) = @parts; @@ -814,6 +809,9 @@ } else { $self = $x; } + + return $downgrade -> new($x, @r) + if defined($downgrade) && $x -> is_int(); return $self -> round(@r); } @@ -836,6 +834,8 @@ $self->import() if $IMPORT == 0; # make require work return if $selfref && $self->modify('bzero'); + return $downgrade->bzero() if defined $downgrade; + $self = bless {}, $class unless $selfref; $self -> {sign} = '+'; @@ -878,6 +878,8 @@ $self->import() if $IMPORT == 0; # make require work return if $selfref && $self->modify('bone'); + return $downgrade->bone() if defined $downgrade; + my $sign = shift; $sign = defined $sign && $sign =~ /^\s*-/ ? "-" : "+"; @@ -918,6 +920,8 @@ unshift @_, __PACKAGE__; } + return $downgrade->binf(@_) if defined $downgrade; + my $self = shift; my $selfref = ref $self; my $class = $selfref || $self; @@ -970,6 +974,8 @@ unshift @_, __PACKAGE__; } + return $downgrade->bnan(@_) if defined $downgrade; + my $self = shift; my $selfref = ref $self; my $class = $selfref || $self; @@ -1050,7 +1056,7 @@ { $r[0] = $self; $class = __PACKAGE__; - $self = $class -> bzero(@r); # initialize + $self = bless {}, $class; # initialize } # ... or if bpi() is called as a method ... @@ -1060,7 +1066,7 @@ if ($selfref) { # bpi() called as instance method return $self if $self -> modify('bpi'); } else { # bpi() called as class method - $self = $class -> bzero(@r); # initialize + $self = bless {}, $class; # initialize } } @@ -1509,14 +1515,21 @@ # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN' $x->{sign} =~ tr/+-/-+/ unless ($x->{sign} eq '+' && $LIB->_is_zero($x->{_m})); - $x; + + return $downgrade -> new($x) + if defined($downgrade) && ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); + return $x; } sub bnorm { # adjust m and e so that m is smallest possible my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - return $x if $x->{sign} !~ /^[+-]$/; # inf, nan etc + # inf, nan etc + if ($x->{sign} !~ /^[+-]$/) { + return $downgrade->new($x) if defined $downgrade; + return $x; + } my $zeros = $LIB->_zeros($x->{_m}); # correct for trailing zeros if ($zeros != 0) { @@ -1540,6 +1553,7 @@ if $LIB->_is_zero($x->{_m}); } + return $downgrade->new($x) if defined($downgrade) && $x->is_int(); $x; } @@ -1614,6 +1628,7 @@ # set up parameters my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { ($class, $x, $y, @r) = objectify(2, @_); @@ -1622,17 +1637,25 @@ return $x if $x->modify('badd'); # inf and NaN handling - if (($x->{sign} !~ /^[+-]$/) || ($y->{sign} !~ /^[+-]$/)) { + if ($x->{sign} !~ /^[+-]$/ || $y->{sign} !~ /^[+-]$/) { + # NaN first - return $x->bnan() if (($x->{sign} eq $nan) || ($y->{sign} eq $nan)); + if ($x->{sign} eq $nan || $y->{sign} eq $nan) { + $x->bnan(); + } + # inf handling - if (($x->{sign} =~ /^[+-]inf$/) && ($y->{sign} =~ /^[+-]inf$/)) { + elsif ($x->{sign} =~ /^[+-]inf$/ && $y->{sign} =~ /^[+-]inf$/) { # +inf++inf or -inf+-inf => same, rest is NaN - return $x if $x->{sign} eq $y->{sign}; - return $x->bnan(); + $x->bnan() if $x->{sign} ne $y->{sign}; } + # +-inf + something => +inf; something +-inf => +-inf - $x->{sign} = $y->{sign}, return $x if $y->{sign} =~ /^[+-]inf$/; + elsif ($y->{sign} =~ /^[+-]inf$/) { + $x->{sign} = $y->{sign}; + } + + return $downgrade->new($x, @r) if defined $downgrade; return $x; } @@ -1641,55 +1664,61 @@ $r[3] = $y; # no push! - # speed: no add for 0+y or x+0 - return $x->bround(@r) if $y->is_zero(); # x+0 - if ($x->is_zero()) # 0+y - { + # for speed: no add for $x + 0 + if ($y->is_zero()) { + $x->bround(@r); + } + + # for speed: no add for 0 + $y + elsif ($x->is_zero()) { # make copy, clobbering up x (modify in place!) $x->{_e} = $LIB->_copy($y->{_e}); $x->{_es} = $y->{_es}; $x->{_m} = $LIB->_copy($y->{_m}); $x->{sign} = $y->{sign} || $nan; - return $x->round(@r); + $x->round(@r); } - # take lower of the two e's and adapt m1 to it to match m2 - my $e = $y->{_e}; - $e = $LIB->_zero() if !defined $e; # if no BFLOAT? - $e = $LIB->_copy($e); # make copy (didn't do it yet) + else { - my $es; + # take lower of the two e's and adapt m1 to it to match m2 + my $e = $y->{_e}; + $e = $LIB->_zero() if !defined $e; # if no BFLOAT? + $e = $LIB->_copy($e); # make copy (didn't do it yet) - ($e, $es) = _e_sub($e, $x->{_e}, $y->{_es} || '+', $x->{_es}); - #($e, $es) = $LIB -> _ssub($e, $y->{_es} || '+', $x->{_e}, $x->{_es}); + my $es; - my $add = $LIB->_copy($y->{_m}); + ($e, $es) = _e_sub($e, $x->{_e}, $y->{_es} || '+', $x->{_es}); + #($e, $es) = $LIB -> _ssub($e, $y->{_es} || '+', $x->{_e}, $x->{_es}); - if ($es eq '-') # < 0 - { - $x->{_m} = $LIB->_lsft($x->{_m}, $e, 10); - ($x->{_e}, $x->{_es}) = _e_add($x->{_e}, $e, $x->{_es}, $es); - #$x->{_m} = $LIB->_lsft($x->{_m}, $e, 10); - #($x->{_e}, $x->{_es}) = $LIB -> _sadd($x->{_e}, $x->{_es}, $e, $es); + my $add = $LIB->_copy($y->{_m}); - } elsif (!$LIB->_is_zero($e)) # > 0 - { - $add = $LIB->_lsft($add, $e, 10); - } - # else: both e are the same, so just leave them + if ($es eq '-') { # < 0 + $x->{_m} = $LIB->_lsft($x->{_m}, $e, 10); + ($x->{_e}, $x->{_es}) = _e_add($x->{_e}, $e, $x->{_es}, $es); + #$x->{_m} = $LIB->_lsft($x->{_m}, $e, 10); + #($x->{_e}, $x->{_es}) = $LIB -> _sadd($x->{_e}, $x->{_es}, $e, $es); + } elsif (!$LIB->_is_zero($e)) { # > 0 + $add = $LIB->_lsft($add, $e, 10); + } - if ($x->{sign} eq $y->{sign}) { - # add - $x->{_m} = $LIB->_add($x->{_m}, $add); - } else { - ($x->{_m}, $x->{sign}) = - _e_add($x->{_m}, $add, $x->{sign}, $y->{sign}); - #($x->{_m}, $x->{sign}) = - # $LIB -> _sadd($x->{_m}, $x->{sign}, $add, $y->{sign}); + # else: both e are the same, so just leave them + + if ($x->{sign} eq $y->{sign}) { + $x->{_m} = $LIB->_add($x->{_m}, $add); + } else { + ($x->{_m}, $x->{sign}) = + _e_add($x->{_m}, $add, $x->{sign}, $y->{sign}); + #($x->{_m}, $x->{sign}) = + # $LIB -> _sadd($x->{_m}, $x->{sign}, $add, $y->{sign}); + } + + # delete trailing zeros, then round + $x->bnorm()->round(@r); } - # delete trailing zeros, then round - $x->bnorm()->round(@r); + return $downgrade->new($x, @r) if defined($downgrade) && $x -> is_int(); + return $x; } sub bsub { @@ -1709,21 +1738,31 @@ return $upgrade -> new($x) -> bsub($upgrade -> new($y), @r) if defined $upgrade && (!$x -> isa($class) || !$y -> isa($class)); - return $x -> round(@r) if $y -> is_zero(); + if ($y -> is_zero()) { + $x -> round(@r); + } else { - # To correctly handle the lone special case $x -> bsub($x), we note the - # sign of $x, then flip the sign from $y, and if the sign of $x did change, - # too, then we caught the special case: - - my $xsign = $x -> {sign}; - $y -> {sign} =~ tr/+-/-+/; # does nothing for NaN - if ($xsign ne $x -> {sign}) { - # special case of $x -> bsub($x) results in 0 - return $x -> bzero(@r) if $xsign =~ /^[+-]$/; - return $x -> bnan(); # NaN, -inf, +inf + # To correctly handle the special case $x -> bsub($x), we note the sign + # of $x, then flip the sign of $y, and if the sign of $x changed too, + # then we know that $x and $y are the same object. + + my $xsign = $x -> {sign}; + $y -> {sign} =~ tr/+-/-+/; # does nothing for NaN + if ($xsign ne $x -> {sign}) { + # special case of $x -> bsub($x) results in 0 + if ($xsign =~ /^[+-]$/) { + $x -> bzero(@r); + } else { + $x -> bnan(); # NaN, -inf, +inf + } + return $downgrade->new($x, @r) if defined $downgrade; + return $x; + } + $x = $x -> badd($y, @r); # badd does not leave internal zeros + $y -> {sign} =~ tr/+-/-+/; # reset $y (does nothing for NaN) } - $x -> badd($y, @r); # badd does not leave internal zeros - $y -> {sign} =~ tr/+-/-+/; # refix $y (does nothing for NaN) + return $downgrade->new($x, @r) + if defined($downgrade) && ($x->is_int() || $x->is_inf() || $x->is_nan()); $x; # already rounded by badd() or no rounding } @@ -1804,7 +1843,11 @@ $x->{sign} = $x->{sign} ne $y->{sign} ? '-' : '+'; # z=inf handling (z=NaN handled above) - $x->{sign} = $z->{sign}, return $x if $z->{sign} =~ /^[+-]inf$/; + if ($z->{sign} =~ /^[+-]inf$/) { + $x->{sign} = $z->{sign}; + return $downgrade->new($x) if defined $downgrade; + return $x; + } # take lower of the two e's and adapt m1 to it to match m2 my $e = $z->{_e}; @@ -1933,9 +1976,6 @@ # x == 0? return wantarray ? ($x, $class->bzero()) : $x if $x->is_zero(); - # upgrade ? - return $upgrade->bdiv($upgrade->new($x), $y, $a, $p, $r) if defined $upgrade; - # we need to limit the accuracy to protect against overflow my $fallback = 0; my (@params, $scale); @@ -2034,8 +2074,14 @@ # clear a/p after round, since user did not request it delete $rem->{_a}; delete $rem->{_p}; } + $x = $downgrade -> new($x) + if defined($downgrade) && $x -> is_int(); + $rem = $downgrade -> new($rem) + if defined($downgrade) && $rem -> is_int(); return ($x, $rem); } + + $x = $downgrade -> new($x) if defined($downgrade) && $x -> is_int(); $x; } @@ -3633,24 +3679,42 @@ croak('bround() needs positive accuracy'); } + return $x if $x->modify('bround'); + my ($scale, $mode) = $x->_scale_a(@_); - return $x if !defined $scale || $x->modify('bround'); # no-op + if (!defined $scale) { # no-op + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } - # scale is now either $x->{_a}, $accuracy, or the user parameter - # test whether $x already has lower accuracy, do nothing in this case - # but do round if the accuracy is the same, since a math operation might - # want to round a number with A=5 to 5 digits afterwards again - return $x if defined $x->{_a} && $x->{_a} < $scale; + # Scale is now either $x->{_a}, $accuracy, or the input argument. Test + # whether $x already has lower accuracy, do nothing in this case but do + # round if the accuracy is the same, since a math operation might want to + # round a number with A=5 to 5 digits afterwards again + + if (defined $x->{_a} && $x->{_a} < $scale) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } # scale < 0 makes no sense # scale == 0 => keep all digits # never round a +-inf, NaN - return $x if ($scale <= 0) || $x->{sign} !~ /^[+-]$/; + + if ($scale <= 0 || $x->{sign} !~ /^[+-]$/) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } # 1: never round a 0 # 2: if we should keep more digits than the mantissa has, do nothing if ($x->is_zero() || $LIB->_len($x->{_m}) <= $scale) { $x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; } @@ -3661,6 +3725,8 @@ $x->{_m} = $m->{value}; # get our mantissa back $x->{_a} = $scale; # remember rounding delete $x->{_p}; # and clear P + + # bnorm() downgrades if necessary, so no need to check whether to downgrade. $x->bnorm(); # del trailing zeros gen. by bround() } @@ -3672,25 +3738,47 @@ my $class = ref($x) || $x; $x = $class->new(shift) if !ref($x); + return $x if $x->modify('bfround'); # no-op + my ($scale, $mode) = $x->_scale_p(@_); - return $x if !defined $scale || $x->modify('bfround'); # no-op + if (!defined $scale) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } # never round a 0, +-inf, NaN + if ($x->is_zero()) { $x->{_p} = $scale if !defined $x->{_p} || $x->{_p} < $scale; # -3 < -2 + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } + + if ($x->{sign} !~ /^[+-]$/) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; } - return $x if $x->{sign} !~ /^[+-]$/; # don't round if x already has lower precision - return $x if (defined $x->{_p} && $x->{_p} < 0 && $scale < $x->{_p}); + if (defined $x->{_p} && $x->{_p} < 0 && $scale < $x->{_p}) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } $x->{_p} = $scale; # remember round in any case delete $x->{_a}; # and clear A if ($scale < 0) { # round right from the '.' - return $x if $x->{_es} eq '+'; # e >= 0 => nothing to round + if ($x->{_es} eq '+') { # e >= 0 => nothing to round + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } $scale = -$scale; # positive for simplicity my $len = $LIB->_len($x->{_m}); # length of mantissa @@ -3710,13 +3798,22 @@ # 1.2345 12345e-4 5 0 4 # do not round after/right of the $dad - return $x if $scale > $dad; # 0.123, scale >= 3 => exit + + if ($scale > $dad) { # 0.123, scale >= 3 => exit + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } # round to zero if rounding inside the $zad, but not for last zero like: # 0.0065, scale -2, round last '0' with following '65' (scale == zad case) - return $x->bzero() if $scale < $zad; - if ($scale == $zad) # for 0.006, scale -3 and trunc - { + if ($scale < $zad) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x->bzero(); + } + + if ($scale == $zad) { # for 0.006, scale -3 and trunc $scale = -$len; } else { # adjust round-point to be inside mantissa @@ -3739,12 +3836,17 @@ # should be the same, so treat it as this $scale = 1 if $scale == 0; # shortcut if already integer - return $x if $scale == 1 && $dbt <= $dbd; + if ($scale == 1 && $dbt <= $dbd) { + return $downgrade->new($x) if defined($downgrade) + && ($x->is_int() || $x->is_inf() || $x->is_nan()); + return $x; + } # maximum digits before dot ++$dbd; if ($scale > $dbd) { # not enough digits before dot, so round to zero + return $downgrade->new($x) if defined($downgrade); return $x->bzero; } elsif ($scale == $dbd) { # maximum @@ -3753,66 +3855,81 @@ $scale = $dbd - $scale; } } + # pass sign to bround for rounding modes '+inf' and '-inf' my $m = bless { sign => $x->{sign}, value => $x->{_m} }, 'Math::BigInt'; $m->bround($scale, $mode); $x->{_m} = $m->{value}; # get our mantissa back + + # bnorm() downgrades if necessary, so no need to check whether to downgrade. $x->bnorm(); } sub bfloor { # round towards minus infinity - my ($class, $x, $a, $p, $r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $x if $x->modify('bfloor'); - return $x if $x->{sign} !~ /^[+-]$/; # nan, +inf, -inf - # if $x has digits after dot - if ($x->{_es} eq '-') { - $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); # cut off digits after dot - $x->{_e} = $LIB->_zero(); # trunc/norm - $x->{_es} = '+'; # abs e - $x->{_m} = $LIB->_inc($x->{_m}) if $x->{sign} eq '-'; # increment if negative + if ($x->{sign} =~ /^[+-]$/) { + # if $x has digits after dot, remove them + if ($x->{_es} eq '-') { + $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); + $x->{_e} = $LIB->_zero(); + $x->{_es} = '+'; + # increment if negative + $x->{_m} = $LIB->_inc($x->{_m}) if $x->{sign} eq '-'; + } + $x->round(@r); } - $x->round($a, $p, $r); + return $downgrade->new($x, @r) if defined($downgrade); + return $x; } sub bceil { # round towards plus infinity - my ($class, $x, $a, $p, $r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $x if $x->modify('bceil'); - return $x if $x->{sign} !~ /^[+-]$/; # nan, +inf, -inf - # if $x has digits after dot - if ($x->{_es} eq '-') { - $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); # cut off digits after dot - $x->{_e} = $LIB->_zero(); # trunc/norm - $x->{_es} = '+'; # abs e - if ($x->{sign} eq '+') { - $x->{_m} = $LIB->_inc($x->{_m}); # increment if positive - } else { - $x->{sign} = '+' if $LIB->_is_zero($x->{_m}); # avoid -0 + # if $x has digits after dot, remove them + if ($x->{sign} =~ /^[+-]$/) { + if ($x->{_es} eq '-') { + $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); + $x->{_e} = $LIB->_zero(); + $x->{_es} = '+'; + if ($x->{sign} eq '+') { + $x->{_m} = $LIB->_inc($x->{_m}); # increment if positive + } else { + $x->{sign} = '+' if $LIB->_is_zero($x->{_m}); # avoid -0 + } } + $x->round(@r); } - $x->round($a, $p, $r); + + return $downgrade->new($x, @r) if defined($downgrade); + return $x; } sub bint { # round towards zero - my ($class, $x, $a, $p, $r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $x if $x->modify('bint'); - return $x if $x->{sign} !~ /^[+-]$/; # nan, +inf, -inf - # if $x has digits after the decimal point - if ($x->{_es} eq '-') { - $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); # cut off digits after dot - $x->{_e} = $LIB->_zero(); # truncate/normalize - $x->{_es} = '+'; # abs e - $x->{sign} = '+' if $LIB->_is_zero($x->{_m}); # avoid -0 + if ($x->{sign} =~ /^[+-]$/) { + # if $x has digits after the decimal point + if ($x->{_es} eq '-') { + $x->{_m} = $LIB->_rsft($x->{_m}, $x->{_e}, 10); # remove fraction part + $x->{_e} = $LIB->_zero(); # truncate/normalize + $x->{_es} = '+'; # abs e + $x->{sign} = '+' if $LIB->_is_zero($x->{_m}); # avoid -0 + } + $x->round(@r); } - $x->round($a, $p, $r); + + return $downgrade->new($x, @r) if defined($downgrade); + return $x; } ############################################################################### @@ -5234,7 +5351,7 @@ =head1 NAME -Math::BigFloat - Arbitrary size floating point math package +Math::BigFloat - arbitrary size floating point math package =head1 SYNOPSIS diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/lib/Math/BigInt/Calc.pm new/Math-BigInt-1.999830/lib/Math/BigInt/Calc.pm --- old/Math-BigInt-1.999829/lib/Math/BigInt/Calc.pm 2021-12-29 19:28:36.000000000 +0100 +++ new/Math-BigInt-1.999830/lib/Math/BigInt/Calc.pm 2022-04-11 08:05:30.000000000 +0200 @@ -7,7 +7,8 @@ use Carp qw< carp croak >; use Math::BigInt::Lib; -our $VERSION = '1.999829'; +our $VERSION = '1.999830'; +$VERSION =~ tr/_//d; our @ISA = ('Math::BigInt::Lib'); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/lib/Math/BigInt/Lib.pm new/Math-BigInt-1.999830/lib/Math/BigInt/Lib.pm --- old/Math-BigInt-1.999829/lib/Math/BigInt/Lib.pm 2021-12-29 19:28:07.000000000 +0100 +++ new/Math-BigInt-1.999830/lib/Math/BigInt/Lib.pm 2022-04-11 08:05:29.000000000 +0200 @@ -4,7 +4,8 @@ use strict; use warnings; -our $VERSION = '1.999829'; +our $VERSION = '1.999830'; +$VERSION =~ tr/_//d; use Carp; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/lib/Math/BigInt.pm new/Math-BigInt-1.999830/lib/Math/BigInt.pm --- old/Math-BigInt-1.999829/lib/Math/BigInt.pm 2021-12-30 17:36:05.000000000 +0100 +++ new/Math-BigInt-1.999830/lib/Math/BigInt.pm 2022-04-11 08:05:29.000000000 +0200 @@ -23,7 +23,8 @@ use Carp qw< carp croak >; use Scalar::Util qw< blessed >; -our $VERSION = '1.999829'; +our $VERSION = '1.999830'; +$VERSION =~ tr/_//d; require Exporter; our @ISA = qw(Exporter); @@ -1642,6 +1643,7 @@ #} sub badd { + # add second arg (BINT or string) to first (BINT) (modifies first) # return result as BINT @@ -1708,7 +1710,7 @@ return $x if $x -> modify('bsub'); - return $upgrade -> new($x) -> bsub($upgrade -> new($y), @r) + return $upgrade -> bsub($upgrade -> new($x), $upgrade -> new($y), @r) if defined $upgrade && (!$x -> isa($class) || !$y -> isa($class)); return $x -> round(@r) if $y -> is_zero(); @@ -2813,7 +2815,7 @@ return $x->bnan() if $x->{sign} !~ /^[+-]\z/; # -inf +inf or NaN => NaN - return $upgrade->new($x)->bsin(@r) if defined $upgrade; + return $upgrade -> bsin($upgrade -> new($x, @r)) if defined $upgrade; require Math::BigFloat; # calculate the result and truncate it to integer @@ -2833,11 +2835,11 @@ return $x->bnan() if $x->{sign} !~ /^[+-]\z/; # -inf +inf or NaN => NaN - return $upgrade->new($x)->bcos(@r) if defined $upgrade; + return $upgrade -> bcos($upgrade -> new($x), @r) if defined $upgrade; require Math::BigFloat; # calculate the result and truncate it to integer - my $t = Math::BigFloat->new($x)->bcos(@r)->as_int(); + my $t = Math::BigFloat -> bcos(Math::BigFloat -> new($x), @r) -> as_int(); $x->bone() if $t->is_one(); $x->bzero() if $t->is_zero(); @@ -4186,10 +4188,10 @@ no strict 'refs'; - # What we upgrade to, if anything. Note that we need the whole chain of - # upgrading, because we accept objects that go through multiple upgrades, - # e.g., when Math::BigInt upgrades to Math::BigFloat which upgrades to - # Math::BigRat. We delay getting the chain until we actually need it. + # What we upgrade to, if anything. Note that we need the whole upgrade + # chain, since there might be multiple levels of upgrading. E.g., class A + # upgrades to class B, which upgrades to class C. Delay getting the chain + # until we actually need it. my @upg = (); my $have_upgrade_chain = 0; @@ -4218,12 +4220,14 @@ next if $ref -> isa($a[0]); - # Upgrading is OK, so skip further tests if the argument is upgraded. + # Upgrading is OK, so skip further tests if the argument is upgraded, + # but first get the whole upgrade chain if we haven't got it yet. unless ($have_upgrade_chain) { my $cls = $class; my $upg = $cls -> upgrade(); while (defined $upg) { + last if $upg eq $cls; push @upg, $upg; $cls = $upg; $upg = $cls -> upgrade(); @@ -5319,7 +5323,7 @@ =head1 NAME -Math::BigInt - Arbitrary size integer/float math package +Math::BigInt - arbitrary size integer math package =head1 SYNOPSIS @@ -5727,18 +5731,25 @@ Set/get the class for upgrading. When a computation might result in a non-integer, the operands are upgraded to this class. This is used for instance -by L<bignum>. The default is C<undef>, thus the following operation creates -a Math::BigInt, not a Math::BigFloat: - - my $i = Math::BigInt->new(123); - my $f = Math::BigFloat->new('123.1'); +by L<bignum>. The default is C<undef>, i.e., no upgrading. - print $i + $f, "\n"; # prints 246 + # with no upgrading + $x = Math::BigInt->new(12); + $y = Math::BigInt->new(5); + print $x / $y, "\n"; # 2 as a Math::BigInt + + # with upgrading to Math::BigFloat + Math::BigInt -> upgrade("Math::BigFloat"); + print $x / $y, "\n"; # 2.4 as a Math::BigFloat + + # with upgrading to Math::BigRat (after loading Math::BigRat) + Math::BigInt -> upgrade("Math::BigRat"); + print $x / $y, "\n"; # 12/5 as a Math::BigRat =item downgrade() -Set/get the class for downgrading. The default is C<undef>. Downgrading is not -done by Math::BigInt. +Set/get the class for downgrading. The default is C<undef>, i.e., no +downgrading. Downgrading is not done by Math::BigInt. =item modify() @@ -5796,8 +5807,8 @@ $x = Math::BigInt->new($str,$A,$P,$R); Creates a new Math::BigInt object from a scalar or another Math::BigInt object. -The input is accepted as decimal, hexadecimal (with leading '0x') or binary -(with leading '0b'). +The input is accepted as decimal, hexadecimal (with leading '0x'), octal (with +leading ('0o') or binary (with leading '0b'). See L</Input> for more info on accepted input formats. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/t/downgrade.t new/Math-BigInt-1.999830/t/downgrade.t --- old/Math-BigInt-1.999829/t/downgrade.t 2021-12-28 20:17:36.000000000 +0100 +++ new/Math-BigInt-1.999830/t/downgrade.t 2022-04-11 08:04:29.000000000 +0200 @@ -1,40 +1,18 @@ # -*- mode: perl; -*- +# Note that this does not test Math::BigFloat upgrading. + use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 164; use Math::BigInt upgrade => 'Math::BigFloat'; -use Math::BigFloat downgrade => 'Math::BigInt', - upgrade => 'Math::BigInt'; - -our ($CLASS, $EXPECTED_CLASS, $LIB); -$CLASS = "Math::BigInt"; -$EXPECTED_CLASS = "Math::BigFloat"; -$LIB = "Math::BigInt::Calc"; # backend +use Math::BigFloat downgrade => 'Math::BigInt'; # simplistic test for now is(Math::BigFloat->downgrade(), 'Math::BigInt', 'Math::BigFloat->downgrade()'); -is(Math::BigFloat->upgrade(), 'Math::BigInt', 'Math::BigFloat->upgrade()'); - -# these downgrade -is(ref(Math::BigFloat->new("inf")), "Math::BigInt", - qq|ref(Math::BigFloat->new("inf"))|); -is(ref(Math::BigFloat->new("-inf")), "Math::BigInt", - qq|ref(Math::BigFloat->new("-inf"))|); -is(ref(Math::BigFloat->new("NaN")), "Math::BigInt", - qq|ref(Math::BigFloat->new("NaN"))|); -is(ref(Math::BigFloat->new("0")), "Math::BigInt", - qq|ref(Math::BigFloat->new("0"))|); -is(ref(Math::BigFloat->new("1")), "Math::BigInt", - qq|ref(Math::BigFloat->new("1"))|); -is(ref(Math::BigFloat->new("10")), "Math::BigInt", - qq|ref(Math::BigFloat->new("10"))|); -is(ref(Math::BigFloat->new("-10")), "Math::BigInt", - qq|ref(Math::BigFloat->new("-10"))|); -is(ref(Math::BigFloat->new("-10.0E1")), "Math::BigInt", - qq|ref(Math::BigFloat->new("-10.0E1"))|); +is(Math::BigInt->upgrade(), 'Math::BigFloat', 'Math::BigInt->upgrade()'); # bug until v1.67: is(Math::BigFloat->new("0.2E0"), "0.2", qq|Math::BigFloat->new("0.2E0")|); @@ -53,4 +31,462 @@ is(Math::BigFloat->bpow("2", "0.5"), $x->bsqrt(), qq|Math::BigFloat->bpow("2", "0.5")|); +################################################################################ +# Verify that constructors downgrade when they should. + +note("Enable downgrading, and see if constructors downgrade"); + +Math::BigFloat -> downgrade("Math::BigInt"); + +# new() + +$x = Math::BigFloat -> new("0.5"); +cmp_ok($x, "==", 0.5); +is(ref $x, "Math::BigFloat", "Creating a 0.5 does not downgrade"); + +$x = Math::BigFloat -> new("4"); +cmp_ok($x, "==", 4, 'new("4")'); +is(ref $x, "Math::BigInt", "Creating a 4 downgrades to Math::BigInt"); + +$x = Math::BigFloat -> new("0"); +cmp_ok($x, "==", 0, 'new("0")'); +is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); + +$x = Math::BigFloat -> new("1"); +cmp_ok($x, "==", 1, 'new("1")'); +is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); + +$x = Math::BigFloat -> new("Inf"); +cmp_ok($x, "==", "Inf", 'new("inf")'); +is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); + +$x = Math::BigFloat -> new("NaN"); +is($x, "NaN", 'new("NaN")'); +is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); + +# bzero() + +$x = Math::BigFloat -> bzero(); +cmp_ok($x, "==", 0, "bzero()"); +is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); + +# bone() + +$x = Math::BigFloat -> bone(); +cmp_ok($x, "==", 1, "bone()"); +is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); + +# binf() + +$x = Math::BigFloat -> binf(); +cmp_ok($x, "==", "Inf", "binf()"); +is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); + +# bnan() + +$x = Math::BigFloat -> bnan(); +is($x, "NaN", "bnan()"); +is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); + +# from_dec() + +$x = Math::BigFloat -> from_dec("3.14e2"); +cmp_ok($x, "==", 314, 'from_dec("3.14e2")'); +is(ref $x, "Math::BigInt", 'from_dec("3.14e2") downgrades to Math::BigInt'); + +# from_hex() + +$x = Math::BigFloat -> from_hex("0x1.3ap+8"); +cmp_ok($x, "==", 314, 'from_hex("3.14e2")'); +is(ref $x, "Math::BigInt", 'from_hex("3.14e2") downgrades to Math::BigInt'); + +# from_oct() + +$x = Math::BigFloat -> from_oct("0o1.164p+8"); +cmp_ok($x, "==", 314, 'from_oct("0o1.164p+8")'); +is(ref $x, "Math::BigInt", 'from_oct("0o1.164p+8") downgrades to Math::BigInt'); + +# from_bin() + +$x = Math::BigFloat -> from_bin("0b1.0011101p+8"); +cmp_ok($x, "==", 314, 'from_bin("0b1.0011101p+8")'); +is(ref $x, "Math::BigInt", + 'from_bin("0b1.0011101p+8") downgrades to Math::BigInt'); + +# from_ieee754() + +$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32"); +cmp_ok($x, "==", 314, 'from_ieee754("\x43\x9d\x00\x00", "binary32")'); +is(ref $x, "Math::BigInt", + 'from_ieee754("\x43\x9d\x00\x00", "binary32") downgrades to Math::BigInt'); + +note("Disable downgrading, and see if constructors downgrade"); + +Math::BigFloat -> downgrade(undef); + +my $half = Math::BigFloat -> new("0.5"); +my $four = Math::BigFloat -> new("4"); +my $zero = Math::BigFloat -> bzero(); +my $inf = Math::BigFloat -> binf(); +my $nan = Math::BigFloat -> bnan(); + +is(ref $half, "Math::BigFloat", "Creating a 0.5 does not downgrade"); +is(ref $four, "Math::BigFloat", "Creating a 4 does not downgrade"); +is(ref $zero, "Math::BigFloat", "Creating a 0 does not downgrade"); +is(ref $inf, "Math::BigFloat", "Creating an Inf does not downgrade"); +is(ref $nan, "Math::BigFloat", "Creating a NaN does not downgrade"); + +################################################################################ +# Verify that other methods downgrade when they should. + +Math::BigFloat -> downgrade("Math::BigInt"); + +# This shouldn't be necessary, but it is. Fixme! + +Math::BigInt -> upgrade(undef); + +# bneg() + +$x = $zero -> copy() -> bneg(); +cmp_ok($x, "==", 0, "-(0) = 0"); +is(ref($x), "Math::BigInt", "-(0) => Math::BigInt"); + +$x = $four -> copy() -> bneg(); +cmp_ok($x, "==", -4, "-(4) = -4"); +is(ref($x), "Math::BigInt", "-(4) => Math::BigInt"); + +$x = $inf -> copy() -> bneg(); +cmp_ok($x, "==", "-inf", "-(Inf) = -Inf"); +is(ref($x), "Math::BigInt", "-(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bneg(); +is($x, "NaN", "-(NaN) = NaN"); +is(ref($x), "Math::BigInt", "-(NaN) => Math::BigInt"); + +# bnorm() + +$x = $zero -> copy() -> bnorm(); +cmp_ok($x, "==", 0, "bnorm(0)"); +is(ref($x), "Math::BigInt", "bnorm(0) => Math::BigInt"); + +$x = $four -> copy() -> bnorm(); +cmp_ok($x, "==", 4, "bnorm(4)"); +is(ref($x), "Math::BigInt", "bnorm(4) => Math::BigInt"); + +$x = $inf -> copy() -> bnorm(); +cmp_ok($x, "==", "inf", "bnorm(Inf)"); +is(ref($x), "Math::BigInt", "bnorm(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bnorm(); +is($x, "NaN", "bnorm(NaN)"); +is(ref($x), "Math::BigInt", "bnorm(NaN) => Math::BigInt"); + +# binc() + +$x = $zero -> copy() -> binc(); +cmp_ok($x, "==", 1, "binc(0)"); +is(ref($x), "Math::BigInt", "binc(0) => Math::BigInt"); + +$x = $four -> copy() -> binc(); +cmp_ok($x, "==", 5, "binc(4)"); +is(ref($x), "Math::BigInt", "binc(4) => Math::BigInt"); + +$x = $inf -> copy() -> binc(); +cmp_ok($x, "==", "inf", "binc(Inf)"); +is(ref($x), "Math::BigInt", "binc(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> binc(); +is($x, "NaN", "binc(NaN)"); +is(ref($x), "Math::BigInt", "binc(NaN) => Math::BigInt"); + +# bdec() + +$x = $zero -> copy() -> bdec(); +cmp_ok($x, "==", -1, "bdec(0)"); +is(ref($x), "Math::BigInt", "bdec(0) => Math::BigInt"); + +$x = $four -> copy() -> bdec(); +cmp_ok($x, "==", 3, "bdec(4)"); +is(ref($x), "Math::BigInt", "bdec(4) => Math::BigInt"); + +$x = $inf -> copy() -> bdec(); +cmp_ok($x, "==", "inf", "bdec(Inf)"); +is(ref($x), "Math::BigInt", "bdec(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bdec(); +is($x, "NaN", "bdec(NaN)"); +is(ref($x), "Math::BigInt", "bdec(NaN) => Math::BigInt"); + +# badd() + +$x = $half -> copy() -> badd($nan); +is($x, "NaN", "0.5 + NaN = NaN"); +is(ref($x), "Math::BigInt", "0.5 + NaN => Math::BigInt"); + +$x = $half -> copy() -> badd($inf); +cmp_ok($x, "==", "+Inf", "0.5 + Inf = Inf"); +is(ref($x), "Math::BigInt", "2.5 + Inf => Math::BigInt"); + +$x = $half -> copy() -> badd($half); +cmp_ok($x, "==", 1, "0.5 + 0.5 = 1"); +is(ref($x), "Math::BigInt", "0.5 + 0.5 => Math::BigInt"); + +$x = $half -> copy() -> badd($half -> copy() -> bneg()); +cmp_ok($x, "==", 0, "0.5 + -0.5 = 0"); +is(ref($x), "Math::BigInt", "0.5 + -0.5 => Math::BigInt"); + +$x = $four -> copy() -> badd($zero); +cmp_ok($x, "==", 4, "4 + 0 = 4"); +is(ref($x), "Math::BigInt", "4 + 0 => Math::BigInt"); + +$x = $zero -> copy() -> badd($four); +cmp_ok($x, "==", 4, "0 + 4 = 4"); +is(ref($x), "Math::BigInt", "0 + 4 => Math::BigInt"); + +$x = $inf -> copy() -> badd($four); +cmp_ok($x, "==", "+Inf", "Inf + 4 = Inf"); +is(ref($x), "Math::BigInt", "Inf + 4 => Math::BigInt"); + +$x = $nan -> copy() -> badd($four); +is($x, "NaN", "NaN + 4 = NaN"); +is(ref($x), "Math::BigInt", "NaN + 4 => Math::BigInt"); + +# bsub() + +$x = $half -> copy() -> bsub($nan); +is($x, "NaN", "0.5 - NaN = NaN"); +is(ref($x), "Math::BigInt", "0.5 - NaN => Math::BigInt"); + +$x = $half -> copy() -> bsub($inf); +cmp_ok($x, "==", "-Inf", "2.5 - Inf = -Inf"); +is(ref($x), "Math::BigInt", "2.5 - Inf => Math::BigInt"); + +$x = $half -> copy() -> bsub($half); +cmp_ok($x, "==", 0, "0.5 + 0.5 = 0"); +is(ref($x), "Math::BigInt", "0.5 - 0.5 => Math::BigInt"); + +$x = $half -> copy() -> bsub($half -> copy() -> bneg()); +cmp_ok($x, "==", 1, "0.5 - -0.5 = 1"); +is(ref($x), "Math::BigInt", "0.5 - -0.5 => Math::BigInt"); + +$x = $four -> copy() -> bsub($zero); +cmp_ok($x, "==", 4, "4 - 0 = 4"); +is(ref($x), "Math::BigInt", "4 - 0 => Math::BigInt"); + +$x = $zero -> copy() -> bsub($four); +cmp_ok($x, "==", -4, "0 - 4 = -4"); +is(ref($x), "Math::BigInt", "0 - 4 => Math::BigInt"); + +$x = $inf -> copy() -> bsub($four); +cmp_ok($x, "==", "Inf", "Inf - 4 = Inf"); +is(ref($x), "Math::BigInt", "Inf - 4 => Math::BigInt"); + +$x = $nan -> copy() -> bsub($four); +is($x, "NaN", "NaN - 4 = NaN"); +is(ref($x), "Math::BigInt", "NaN - 4 => Math::BigInt"); + +# bmul() + +$x = $zero -> copy() -> bmul($four); +cmp_ok($x, "==", 0, "bmul(0, 4) = 0"); +is(ref($x), "Math::BigInt", "bmul(0, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmul($four); +cmp_ok($x, "==", 16, "bmul(4, 4) = 16"); +is(ref($x), "Math::BigInt", "bmul(4, 4) => Math::BigInt"); + +$x = $inf -> copy() -> bmul($four); +cmp_ok($x, "==", "inf", "bmul(Inf, 4) = Inf"); +is(ref($x), "Math::BigInt", "bmul(Inf, 4) => Math::BigInt"); + +$x = $nan -> copy() -> bmul($four); +is($x, "NaN", "bmul(NaN, 4) = NaN"); +is(ref($x), "Math::BigInt", "bmul(NaN, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmul("0.5"); +cmp_ok($x, "==", 2, "bmul(4, 0.5) = 2"); +is(ref($x), "Math::BigInt", "bmul(4, 0.5) => Math::BigInt"); + +# bmuladd() + +$x = $zero -> copy() -> bmuladd($four, $four); +cmp_ok($x, "==", 4, "bmuladd(0, 4, 4) = 4"); +is(ref($x), "Math::BigInt", "bmuladd(0, 4, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmuladd($four, $four); +cmp_ok($x, "==", 20, "bmuladd(4, 4, 4) = 20"); +is(ref($x), "Math::BigInt", "bmuladd(4, 4, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmuladd($four, $inf); +cmp_ok($x, "==", "inf", "bmuladd(4, 4, Inf) = Inf"); +is(ref($x), "Math::BigInt", "bmuladd(4, 4, Inf) => Math::BigInt"); + +$x = $inf -> copy() -> bmuladd($four, $four); +cmp_ok($x, "==", "inf", "bmuladd(Inf, 4, 4) = Inf"); +is(ref($x), "Math::BigInt", "bmuladd(Inf, 4, 4) => Math::BigInt"); + +$x = $inf -> copy() -> bmuladd($four, $four); +cmp_ok($x, "==", "inf", "bmuladd(Inf, 4, 4) = Inf"); +is(ref($x), "Math::BigInt", "bmuladd(Inf, 4, 4) => Math::BigInt"); + +$x = $nan -> copy() -> bmuladd($four, $four); +is($x, "NaN", "bmuladd(NaN, 4, 4) = NaN"); +is(ref($x), "Math::BigInt", "bmuladd(NaN, 4, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmuladd("0.5", $four); +cmp_ok($x, "==", 6, "bmuladd(4, 0.5, 4) = 6"); +is(ref($x), "Math::BigInt", "bmuladd(4, 0.5, 4) => Math::BigInt"); + +# bdiv() + +# bmod() + +# bmodpow() + +# bpow() + +# blog() + +# bexp() + +# bnok() + +# bsin() + +# bcos() + +# batan() + +# batan() + +# bsqrt() + +# broot() + +# bfac() + +# bdfac() + +# btfac() + +# bmfac() + +# blsft() + +# brsft() + +# band() + +# bior() + +# bxor() + +# bnot() + +# bround() + +# Add tests for rounding a non-integer to an integer. Fixme! + +$x = $zero -> copy() -> bround(); +cmp_ok($x, "==", 0, "bround(0)"); +is(ref($x), "Math::BigInt", "bround(0) => Math::BigInt"); + +$x = $four -> copy() -> bround(); +cmp_ok($x, "==", 4, "bround(4)"); +is(ref($x), "Math::BigInt", "bround(4) => Math::BigInt"); + +$x = $inf -> copy() -> bround(); +cmp_ok($x, "==", "inf", "bround(Inf)"); +is(ref($x), "Math::BigInt", "bround(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bround(); +is($x, "NaN", "bround(NaN)"); +is(ref($x), "Math::BigInt", "bround(NaN) => Math::BigInt"); + +# bfround() + +# Add tests for rounding a non-integer to an integer. Fixme! + +$x = $zero -> copy() -> bfround(); +cmp_ok($x, "==", 0, "bfround(0)"); +is(ref($x), "Math::BigInt", "bfround(0) => Math::BigInt"); + +$x = $four -> copy() -> bfround(); +cmp_ok($x, "==", 4, "bfround(4)"); +is(ref($x), "Math::BigInt", "bfround(4) => Math::BigInt"); + +$x = $inf -> copy() -> bfround(); +cmp_ok($x, "==", "inf", "bfround(Inf)"); +is(ref($x), "Math::BigInt", "bfround(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bfround(); +is($x, "NaN", "bfround(NaN)"); +is(ref($x), "Math::BigInt", "bfround(NaN) => Math::BigInt"); + +# bfloor() + +$x = $half -> copy() -> bfloor(); +cmp_ok($x, "==", 0, "bfloor(0)"); +is(ref($x), "Math::BigInt", "bfloor(0) => Math::BigInt"); + +$x = $inf -> copy() -> bfloor(); +cmp_ok($x, "==", "Inf", "bfloor(Inf)"); +is(ref($x), "Math::BigInt", "bfloor(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bfloor(); +is($x, "NaN", "bfloor(NaN)"); +is(ref($x), "Math::BigInt", "bfloor(NaN) => Math::BigInt"); + +# bceil() + +$x = $half -> copy() -> bceil(); +cmp_ok($x, "==", 1, "bceil(0)"); +is(ref($x), "Math::BigInt", "bceil(0) => Math::BigInt"); + +$x = $inf -> copy() -> bceil(); +cmp_ok($x, "==", "Inf", "bceil(Inf)"); +is(ref($x), "Math::BigInt", "bceil(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bceil(); +is($x, "NaN", "bceil(NaN)"); +is(ref($x), "Math::BigInt", "bceil(NaN) => Math::BigInt"); + +# bint() + +$x = $half -> copy() -> bint(); +cmp_ok($x, "==", 0, "bint(0)"); +is(ref($x), "Math::BigInt", "bint(0) => Math::BigInt"); + +$x = $inf -> copy() -> bint(); +cmp_ok($x, "==", "Inf", "bint(Inf)"); +is(ref($x), "Math::BigInt", "bint(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bint(); +is($x, "NaN", "bint(NaN)"); +is(ref($x), "Math::BigInt", "bint(NaN) => Math::BigInt"); + +# bgcd() + +# blcm() + +# mantissa() ? + +# exponent() ? + +# parts() ? + +# sparts() + +# nparts() + +# eparts() + +# dparts() + +# fparts() + +# numerator() + +# denominator() + #require 'upgrade.inc'; # all tests here for sharing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/t/upgrade.t new/Math-BigInt-1.999830/t/upgrade.t --- old/Math-BigInt-1.999829/t/upgrade.t 2021-12-28 20:17:36.000000000 +0100 +++ new/Math-BigInt-1.999830/t/upgrade.t 2022-04-11 08:04:29.000000000 +0200 @@ -4,11 +4,29 @@ use warnings; use Test::More tests => 2134 # tests in require'd file - + 2; # tests in this file + + 6; # tests in this file -use Math::BigInt upgrade => 'Math::BigFloat'; +use Math::BigInt; use Math::BigFloat; +my $x = Math::BigInt -> new(9); +my $y = Math::BigInt -> new(4); + +# Without upgrading. + +my $zi = $x / $y; +cmp_ok($zi, "==", 2, "9/4 = 2 without upgrading"); +is(ref($zi), "Math::BigInt", "9/4 gives a Math::BigInt without upgrading"); + +# With upgrading. + +Math::BigInt -> upgrade("Math::BigFloat"); +my $zf = $x / $y; +cmp_ok($zf, "==", 2.25, "9/4 = 2.25 with upgrading"); +is(ref($zf), "Math::BigFloat", "9/4 gives a Math::BigFloat with upgrading"); + +# Other tests. + our ($CLASS, $EXPECTED_CLASS, $LIB); $CLASS = "Math::BigInt"; $EXPECTED_CLASS = "Math::BigFloat"; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Math-BigInt-1.999829/xt/release/git.t new/Math-BigInt-1.999830/xt/release/git.t --- old/Math-BigInt-1.999829/xt/release/git.t 2021-12-28 20:17:37.000000000 +0100 +++ new/Math-BigInt-1.999830/xt/release/git.t 2022-04-11 08:04:29.000000000 +0200 @@ -132,7 +132,7 @@ while (defined(my $line = <$fh>)) { if ($line =~ /^(\S+)/) { my $verstr = $1; - if ($verstr =~ / ^ v? ( \d+ ( \. \d+ )? ) $ /ix) { + if ($verstr =~ / ^ v? ( \d+ ( \. \d+ ( _ \d+ )* )? ) $ /ix) { my $vernum = $1; $vernum =~ tr/_//d; push @vers, [ $verstr, $vernum ]; @@ -171,7 +171,7 @@ $pipe -> reader(@args); while (defined(my $tag = <$pipe>)) { $tag =~ s/\s+\z//; - if ($tag =~ / ^ v? ( \d+ ( \. \d+ )? ) /ix) { + if ($tag =~ / ^ v? ( \d+ ( \. \d+ ( _ \d+ )* )? ) /ix) { my $vernum = $1; $vernum =~ tr/_//d; push @tags, [ $tag, $vernum ];