Commit 59a48a5e authored by gregor herrmann's avatar gregor herrmann

New upstream version 1.999811

parent 17b55f34
2017-03-15 v1.999811 pjacklam
* Fix an old in the Math::BigFloat methods as_hex(), as_oct(), and as_bin()
methods resulting in loss of accuracy. This bug was introduced in bug in
Math-BigInt-1.76. Due to a naive copy and paste by me, and lack of tests,
this bug was also present in the newer to_hex(), to_oct(), and to_bin()
methods. This shows the bug, as it did not print "0xffff...":
print Math::BigFloat -> from_hex("f" x 30) -> as_hex();
* Fix incorrect formatting in the output from the Math::BigFloat methods
to_hex(), to_oct(), and to_bin() when the output was zero. A prefix was
added when it shouldn't have been.
* Add tests to bigintpm.inc and bigfltpm.inc for better testing of as_hex(),
as_oct(), and as_bin() as well as to_hex(), to_oct(), and to_bin().
* "Synchronize" tests and code formatting in bigintpm.inc and bigfltpm.inc.
2017-03-01 v1.999810 pjacklam
* CPAN RT #120240 revealed that the problems with undefined values is still
present. After a close examination, I believe the only way to get this
really working is to to make blog() call objectify() differently depending
on whether the base for the logarithm is undefined or not. That way we can
avoid objectify() converting the undefined value to a zero. Ideally, we
should warn about undefined values when used in any other context, but we'll
handle that in a later release. See also the related changelog entry for
v1.999801.
* Fix the way the argument count is computed in objectify(). When an argument
count of 0 is given, it means that we should objectify all input arguments.
However, it turned out that the actual argument count was computed
incorrectly.
* Fix CPAN RT #120242 rearding c3 method resolution.
2017-02-10 v1.999809 pjacklam
* When a new method is added to Math::BigInt or Math::BigFloat, and this new
method requires a new backend library method, die with a suitable error
message if the installed backend library does not support this new method.
The error message says that the method requires a newer version of the
backend library.
* Fix typos in Math::BigFloat and Math::BigInt.
* Add bfib() and blucas() to Math::BigInt. They return Fibonacci and Lucas
numbers, respectively. The actual computation of the numbers is done by the
backend library. Documented both methods in POD. Add test files bfib-mbi.t
and blucas-mbi.t.
* Add _fib() and _lucas() to Math::BigInt::Lib. They return Fibonacci and
Lucas numbers, respectively. Document both methods in POD. Add test files
author-lib-arithmetic-unary-_fib.t and author-lib-arithmetic-unary-_lucas.t.
2017-01-11 v1.999808 pjacklam
* In Math::BigInt and Math::BigFloat, add methods bdfac() for double
......
......@@ -66,8 +66,12 @@ t/author-lib-arithmetic-unary-_dfac.dat
t/author-lib-arithmetic-unary-_dfac.t
t/author-lib-arithmetic-unary-_fac.dat
t/author-lib-arithmetic-unary-_fac.t
t/author-lib-arithmetic-unary-_fib.dat
t/author-lib-arithmetic-unary-_fib.t
t/author-lib-arithmetic-unary-_inc.dat
t/author-lib-arithmetic-unary-_inc.t
t/author-lib-arithmetic-unary-_lucas.dat
t/author-lib-arithmetic-unary-_lucas.t
t/author-lib-arithmetic-unary-_sqrt.dat
t/author-lib-arithmetic-unary-_sqrt.t
t/author-lib-bitwise-_and.dat
......@@ -133,6 +137,7 @@ t/bdstr-mbf.t
t/bdstr-mbi.t
t/bestr-mbf.t
t/bestr-mbi.t
t/bfib-mbi.t
t/big_pi_e.t
t/bigfltpm.inc
t/bigfltpm.t
......@@ -142,6 +147,7 @@ t/bigintpm.t
t/bigints.t
t/biglog.t
t/bigroot.t
t/blucas-mbi.t
t/bnstr-mbf.t
t/bnstr-mbi.t
t/bsstr-mbf.t
......
......@@ -10,3 +10,4 @@ pm_to_blib
\.*tmp
.*\.patch\z
^Math-BigInt-
~\z
......@@ -39,6 +39,6 @@
}
},
"release_status" : "stable",
"version" : "1.999808",
"version" : "1.999811",
"x_serialization_backend" : "JSON::PP version 2.27400"
}
......@@ -21,5 +21,5 @@ requires:
Math::Complex: '1.39'
Test::More: '0.94'
perl: '5.006001'
version: '1.999808'
version: '1.999811'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
......@@ -15,15 +15,15 @@ not run its Makefile.PL or Build.PL.
Hash: SHA1
SHA1 20104176cd4b0623c201cdb2c9583056898b2afc BUGS
SHA1 c9d01c8a0b967b6d7bcb167577cea683de289ad6 CHANGES
SHA1 3688157c3c5e324465ac2a102b4ca0368874bc62 CHANGES
SHA1 a40e6f05bfd2a3e0542cf9e4971b1d48100eb2fd CREDITS
SHA1 8d0b726d78afa344fb12508e1b027079699570e4 GOALS
SHA1 fe61299e80a1dca48fbaa33f0869e3238ec07c70 HISTORY
SHA1 d7c83d8f89b92a3262a01eb2778d39402e77263a LICENSE
SHA1 010b8d09bcacc327cc1783c136128fe5a135bd6f MANIFEST
SHA1 86df44fbe1ea7a68897113f0e327d0f0c25b91e3 MANIFEST.SKIP
SHA1 ec72085ca73637be0747390379306cbaf6934f18 META.json
SHA1 ca7ec6499f5c0980861ea901a656e8aba89d4b48 META.yml
SHA1 66ec462f7cac003832200f3132b2426d5b1c4edd MANIFEST
SHA1 5e76f3cc33453fc0617509755b82695402ca81c5 MANIFEST.SKIP
SHA1 3814f79c63b8f54416fd59033e199fbdf9ef9bbb META.json
SHA1 37e9b7a5b2d6102fe58eb6e98cc40d93ca76b7d6 META.yml
SHA1 64057848e0b32a6dc4666981c40443fad32197ff Makefile.PL
SHA1 4e2191d1724e699862efc5350f480c8e02755112 NEW
SHA1 813c62e6d3edd18b7b634765ecbd75b2cd6389a0 README
......@@ -31,21 +31,21 @@ SHA1 bf92a92718fe3dae1b24983b48064e638b23609f TODO
SHA1 a8ffc7d3270e481c9d24603a74ba2c0f46cae0e3 examples/1000.txt
SHA1 3295c03031e6a50199c1acc743a3f3276e6ae59d examples/bigprimes.pl
SHA1 989bfc0ad145d0f42b1eb65e83d9de018a7ee150 examples/prime.pl
SHA1 601489d3b0245fdf569cb8d9906069d49c7cbf1c lib/Math/BigFloat.pm
SHA1 5fa26e901c52b04247b54b726772fbb851b9dd7a lib/Math/BigInt.pm
SHA1 f78149fb76d10aca19ca5c62c1d247d26728b961 lib/Math/BigInt/Calc.pm
SHA1 a0133bcbfe71d54739aaf2da8a3dafcb29c94ee6 lib/Math/BigInt/CalcEmu.pm
SHA1 22673ff709a3335376c76767324143de3c29f78b lib/Math/BigInt/Lib.pm
SHA1 c7dbeb239c255749eac2a61266830bcdba464f66 lib/Math/BigFloat.pm
SHA1 95ecb2c5618146b7cf8e42260567dd8c23246ede lib/Math/BigInt.pm
SHA1 1c5c504e33b3bbf83ccc4448f5b839b7c7f4a5a5 lib/Math/BigInt/Calc.pm
SHA1 5c8bcc7494ea09bbe4345f950a3f7bf890b0e478 lib/Math/BigInt/CalcEmu.pm
SHA1 41b9aa1fd37a233e9d7af2de0d09b9e0f1ff551b lib/Math/BigInt/Lib.pm
SHA1 385cc7ed3bf3e6290640b9880445ca9a3dea629e t/00sig.t
SHA1 062a7e33e6697b19e002cdb11f3c648fe6669139 t/01load.t
SHA1 b2ed9206ca5b69ec3b8bbf850bf4b6dfde518e7e t/02pod.t
SHA1 47c879490e1a6229d0464805679c67660af7b4b3 t/03podcov.t
SHA1 a323fbde83f97abdedc14ff923a2ecabb1333e2d t/Math/BigFloat/Subclass.pm
SHA1 ed28da618fe54da4ab6262d2459896b61c38b597 t/Math/BigFloat/Subclass.pm
SHA1 079c95d9ecb1e4c0a863c60d66c15c407b162ad9 t/Math/BigInt/BareCalc.pm
SHA1 e8bff535d485feb97b03fe8217f3446a28d82fe8 t/Math/BigInt/Lib/Minimal.pm
SHA1 e7eef054ec92ff5d259edfb9b39c932db74ffad3 t/Math/BigInt/Lib/TestUtil.pm
SHA1 54f99a0bf52a848dbf34e459daef0df4694e543a t/Math/BigInt/Scalar.pm
SHA1 69c77dbdb12adb852836eaebb0c6957154de4e19 t/Math/BigInt/Subclass.pm
SHA1 3f15444c9efd2720beab72481ce950192932794f t/Math/BigInt/Subclass.pm
SHA1 6d11459530fb13a9e3c490cc3cb9040f9b78cdb4 t/_e_math.t
SHA1 0d67c764487923bd2427c7ac20778308bea548d6 t/alias.inc
SHA1 bcf4632983c6b52fcc7d694a60899576a4ec8fbe t/author-batan-mbf.t
......@@ -91,8 +91,12 @@ SHA1 acc3c86db320c6d7f60ac77c2416ed74528ad0f1 t/author-lib-arithmetic-unary-_dfa
SHA1 4ced5df6d99a24180efe48e9818b97966937e0b3 t/author-lib-arithmetic-unary-_dfac.t
SHA1 0611b9f6f31bec9174d4cee4d20899e023feb0ca t/author-lib-arithmetic-unary-_fac.dat
SHA1 8e2f461b24972926f9777d792d96b20e4793eea9 t/author-lib-arithmetic-unary-_fac.t
SHA1 0b68c69d88f0b52a80a5c9dbcc9c98a4e7fcb57c t/author-lib-arithmetic-unary-_fib.dat
SHA1 4f0bf6a7fcfce9e7c4bda59a2dcc60975a6265c7 t/author-lib-arithmetic-unary-_fib.t
SHA1 cc89be7f70dd75c8fef0cbf6f0bc24c9bd4b5ba2 t/author-lib-arithmetic-unary-_inc.dat
SHA1 ea13d6d205a217f2967c5cb0f42d57a971899583 t/author-lib-arithmetic-unary-_inc.t
SHA1 da063137e88f2212c3aa1efc54eb7a1628aaf0b0 t/author-lib-arithmetic-unary-_lucas.dat
SHA1 76bd647012a854ec7fe37e71711c24f169309d7c t/author-lib-arithmetic-unary-_lucas.t
SHA1 945458ba0c81213b1e7ee6a277cc47e425108f3e t/author-lib-arithmetic-unary-_sqrt.dat
SHA1 c635eaae7dc0bb20b244ee241a2d4cdf1ec6e25b t/author-lib-arithmetic-unary-_sqrt.t
SHA1 fa4e6baa4542ce315a681a6da751a37751e39ca6 t/author-lib-bitwise-_and.dat
......@@ -151,29 +155,31 @@ SHA1 518c629dc74fb7c1fef9ca1ebc0688db2964921d t/author-lib.t
SHA1 75a086f2d747b58afb4fb2de412b2217b2cf11f0 t/author-numify-mbf.t
SHA1 dc386a2bd21a363c42f3dcbf7e9745632cd3d633 t/author-numify-mbi.t
SHA1 096ed0c89fca2f4be7ee211521dbc74a2cd39eaf t/author-relop-mbi-mbf.t
SHA1 9bcf9f3a49e5e1bee5223ad95548affb1d2bc02e t/bare_mbf.t
SHA1 2a141825c46936a62db3568227923e7153c982ec t/bare_mbi.t
SHA1 590c5c6aae1b8af3a65115f2cc511994a08d44fd t/bare_mbf.t
SHA1 4730c87b2161836f3ad9fc20c836fcb8680779db t/bare_mbi.t
SHA1 f172265d69c5dc6879cb650b5ba1f34374104616 t/bare_mif.t
SHA1 75daf2820044e03c6a073e2633122c1182da018c t/bdstr-mbf.t
SHA1 7e5d1349b113ad024efe066e42a50bc9ff595550 t/bdstr-mbi.t
SHA1 08654f0fe1eb27ec069f403ce433ccb588f7a29f t/bestr-mbf.t
SHA1 ed5547fcac28f575d1bbd2e3e5f6fe5f6146c321 t/bestr-mbi.t
SHA1 96bd46866ad45ceed4eedc1c33a3105ee1ae2bc5 t/bfib-mbi.t
SHA1 e6bd71c0d21c7199106b5580e2fbd186b6b01d29 t/big_pi_e.t
SHA1 709cef0e13fd2a85f007482877bfdcf42bf5f8d4 t/bigfltpm.inc
SHA1 b79b49c9653b1ab538753a9857d3bd1dc134f1a0 t/bigfltpm.t
SHA1 b6e1b050cc36155e07df1e6f3b495c9f8a15a192 t/bigfltpm.inc
SHA1 9ce986af92d35f94702607dcb4346e4f242a42b2 t/bigfltpm.t
SHA1 b601bb8f081b3e2c5626995e66f3fe1cdef8af6e t/bigintc.t
SHA1 f05bb12c2eaafa41b4409146cc160d37d8424670 t/bigintpm.inc
SHA1 635900d55b826d5221ef77bc760f498718e77810 t/bigintpm.t
SHA1 b27b994895f5f08dc63f93ce42b5952520f29820 t/bigintpm.inc
SHA1 ebc6a2433d3cafabb0ee182e59fd3627145e8f46 t/bigintpm.t
SHA1 9aac2eda0e723298c8f9ddadffde39a8c16fb171 t/bigints.t
SHA1 3f4bf6d2717d47117ab987cc6ff8d38991cdd383 t/biglog.t
SHA1 128c6cb0ef562637e7b44bafa83188b058392392 t/bigroot.t
SHA1 aab5180a38420e248d2ca0b515dab55c342bee5a t/blucas-mbi.t
SHA1 2f7b4a37d45938057e6faa5db808e1df7fb7f043 t/bnstr-mbf.t
SHA1 a4344b91b9508dcb85645a4b87268f2c11576cae t/bnstr-mbi.t
SHA1 8d5692fa1ab8b84bb816f83c0d51c409de8f13b5 t/bsstr-mbf.t
SHA1 c97164e3ae794f8d2f141be42e5f7af4f2dd674b t/bsstr-mbi.t
SHA1 dcaf0d82455c9a814da942383cbceb2da7ad3a4c t/calling-class-methods.t
SHA1 63e873c5cdcccfb338fb9220d33904027865e9cf t/calling-instance-methods.t
SHA1 d3838262b3bd03e4e94648cc8961630c387106ac t/calling.t
SHA1 738f639a5d08f788760977c8838e51ecf2663f6a t/calling.t
SHA1 c403d1c64ae6c3b803fc8cd0d10a1df15219057f t/config.t
SHA1 af01ecfb6f43bb518c67185eb063c196e2dbdc48 t/const_mbf.t
SHA1 17eb15c35392945a5b3ed2b711f7d166fca294de t/constant.t
......@@ -215,28 +221,28 @@ SHA1 d4dc89382fcdc28f4a2a70eacb8204445b327072 t/rt-16221.t
SHA1 a23c4c5027ff03a39504f43936de66606bb11703 t/sparts-mbf.t
SHA1 f766d72f97efd1328b8bc18edd0f9a2b5550c870 t/sparts-mbi.t
SHA1 ab253275ec4288308f6ea6ecf0744e24cb3c356a t/sub_ali.t
SHA1 7b25cae704b5574d658858700ff3624fc563e722 t/sub_mbf.t
SHA1 c5d499796b7ceafad0e228828619514df4773df4 t/sub_mbi.t
SHA1 3a71b6973d0621a741e13dcd5390000c6c576086 t/sub_mbf.t
SHA1 e094f0cfd091f662cbc1f67a0a31705e41c9232c t/sub_mbi.t
SHA1 8a1adad6483302054e1c14af6e09fb72e8bfec91 t/sub_mif.t
SHA1 b9f56157a8517bce2e7b1bae4c989d58546f5b2c t/trap.t
SHA1 308a86ca4f8be1884927b2f2303f6af1cdc75403 t/upgrade.inc
SHA1 bf2b5c05eabe003ec82a46e0ae931f609ec3b896 t/upgrade.t
SHA1 df0e45b746691e397ed8e80d88df15459b349483 t/upgrade2.t
SHA1 12b27f15d45fd7dd1c69b5b678373fcba7e6a04d t/upgradef.t
SHA1 257bcadfc428cc61445eb24c57b515449c24e636 t/upgradef.t
SHA1 69b741efceefd35226a10e8daccf30805bbfb447 t/use.t
SHA1 4929caee039e617d8ced7339e8e99b8a18330b56 t/use_lib1.t
SHA1 32d44e17e2a03d0c5abe72b1414e79bf02ea821e t/use_lib2.t
SHA1 ccc05714cf95f7394dd51a0bf976e74e8f62dfe7 t/use_lib3.t
SHA1 5b4760d5c552d8857a665180a444a98fb5017ca2 t/use_lib4.t
SHA1 6f8e43710067bed0b0872fafdeb751c9a68732c4 t/use_mbfw.t
SHA1 0a82a7eb45e422b6fb8301400fdd98f8a3ec5886 t/with_sub.t
SHA1 d54fb22dd59d13eab7ee2cc04d05bba5401a5099 t/with_sub.t
-----BEGIN PGP SIGNATURE-----
iQEcBAEBAgAGBQJYdnvaAAoJEGcmPl2fr166wJYIAK6RbV7DdOaev1H9fZzgsDc9
PDAZCq+aL3Z/GNR4Lz2XafFGk252q0NNOHZmSdrZYEiIMlg2Qr4RgAVHeYMQdjHO
ahLpKLyZpKRDWAR6qCTpgyg3+I95YY41biSG1xAQPEMsHjekEPWasfDmJ9HM2/y4
jM7twYal/PR/eh0YCAk3DCPF0wxFuJkriXdKZ4szK0IVOfzzPfMeu0VlicsvuyWR
YDmJzww0En9ZdZaXxFN5huKlfo/Ps15JZyAn91G7o6SybhMqu9gnv868uUvh+AXz
CgtKRA/HQboG49jUmCUJc9Q6JEdnEvFUovj0HZGGJpyL3FEaEsMAVDcEn0+fmlg=
=9cSr
iQEcBAEBAgAGBQJYyRaUAAoJEGcmPl2fr166VZUIAJBK4p/1MTcOr0f3QqGRs9Y1
yiTLJBajV7sFJCmo+7erQYpZs+qrwP5O4ycLuAmFH0J4g63Cdnfe8PQx2JD91LCO
6jK+88ZgJomcORdKhKfK+SniMpY3VaY/FwWHAK1K+nLmWbS1I8hVwoEuS1FAbhlk
ydFKpak9JIEHjPsgsZjAo1thK560+MJnphRFixa7uFsYMtd72UkQdG7HngTTCx6I
mnoaPWb0fFxisApXB8JhNMKCS4TZSiodBJEWoBMhwGtBkn4Szw3Jy7XUrZ9r+RWa
NkPdF5dF5dq/4YaN4N6RMeIG5FQK3B0NWsJSQWnivtESe6Zai79C/NpTLpv0Iek=
=wZed
-----END PGP SIGNATURE-----
......@@ -19,7 +19,7 @@ use warnings;
use Carp ();
use Math::BigInt ();
our $VERSION = '1.999808';
our $VERSION = '1.999811';
require Exporter;
our @ISA = qw/Math::BigInt/;
......@@ -2143,16 +2143,24 @@ sub bpow {
}
sub blog {
my ($class, $x, $base, $a, $p, $r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(2, @_);
# 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
# constant.
# If called as $x -> blog() or $x -> blog(undef), don't objectify the
# undefined base, since undef signals that the base is Euler's number.
#unless (ref($x) && !defined($base)) {
# # objectify is costly, so avoid it
# if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) {
# ($class, $x, $base, $a, $p, $r) = objectify(2, @_);
# }
#}
my ($class, $x, $base, $a, $p, $r);
# Don't objectify the base, since an undefined base, as in $x->blog() or
# $x->blog(undef) signals that the base is Euler's number.
if (!ref($_[0]) && $_[0] =~ /^[A-Za-z]|::/) {
# E.g., Math::BigFloat->blog(256, 2)
($class, $x, $base, $a, $p, $r) =
defined $_[2] ? objectify(2, @_) : objectify(1, @_);
} else {
# E.g., Math::BigFloat::blog(256, 2) or $x->blog(2)
($class, $x, $base, $a, $p, $r) =
defined $_[1] ? objectify(2, @_) : objectify(1, @_);
}
return $x if $x->modify('blog');
......@@ -3232,7 +3240,6 @@ sub bfac {
if (($x->{sign} ne '+') || # inf, NaN, <0 etc => NaN
($x->{_es} ne '+')); # digits after dot?
# use BigInt's bfac() for faster calc
if (! $MBI->_is_zero($x->{_e})) {
$x->{_m} = $MBI->_lsft($x->{_m}, $x->{_e}, 10); # change 12e1 to 120e0
$x->{_e} = $MBI->_zero(); # normalize
......@@ -3257,7 +3264,9 @@ sub bdfac {
if (($x->{sign} ne '+') || # inf, NaN, <0 etc => NaN
($x->{_es} ne '+')); # digits after dot?
# use BigInt's bdfac() for faster calc
Carp::croak("bdfac() requires a newer version of the $MBI library.")
unless $MBI->can('_dfac');
if (! $MBI->_is_zero($x->{_e})) {
$x->{_m} = $MBI->_lsft($x->{_m}, $x->{_e}, 10); # change 12e1 to 120e0
$x->{_e} = $MBI->_zero(); # normalize
......@@ -4032,10 +4041,11 @@ sub bestr {
sub to_hex {
# return number as hexadecimal string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
return '0x0' if $x->is_zero();
return '0' if $x->is_zero();
return $nan if $x->{_es} ne '+'; # how to do 1e-1 in hex?
......@@ -4043,12 +4053,13 @@ sub to_hex {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->to_hex();
my $str = $MBI->_to_hex($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub to_oct {
# return number as octal digit string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
......@@ -4060,16 +4071,17 @@ sub to_oct {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->to_oct();
my $str = $MBI->_to_oct($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub to_bin {
# return number as binary digit string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
return '0b0' if $x->is_zero();
return '0' if $x->is_zero();
return $nan if $x->{_es} ne '+'; # how to do 1e-1 in binary?
......@@ -4077,12 +4089,13 @@ sub to_bin {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->to_bin();
my $str = $MBI->_to_bin($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub as_hex {
# return number as hexadecimal string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
......@@ -4094,16 +4107,17 @@ sub as_hex {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->as_hex();
my $str = $MBI->_as_hex($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub as_oct {
# return number as octal digit string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
return '0' if $x->is_zero();
return '00' if $x->is_zero();
return $nan if $x->{_es} ne '+'; # how to do 1e-1 in octal?
......@@ -4111,12 +4125,13 @@ sub as_oct {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->as_oct();
my $str = $MBI->_as_oct($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub as_bin {
# return number as binary digit string (only for integers defined)
my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_);
return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc
......@@ -4128,8 +4143,8 @@ sub as_bin {
if (! $MBI->_is_zero($x->{_e})) { # > 0
$z = $MBI->_lsft($z, $x->{_e}, 10);
}
$z = Math::BigInt->new($x->{sign} . $MBI->_num($z));
$z->as_bin();
my $str = $MBI->_as_bin($z);
return $x->{sign} eq '-' ? "-$str" : $str;
}
sub numify {
......
......@@ -20,7 +20,7 @@ use warnings;
use Carp ();
our $VERSION = '1.999808';
our $VERSION = '1.999811';
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(objectify bgcd blcm);
......@@ -2385,14 +2385,19 @@ sub blog {
# value is used as the base, otherwise the base is assumed to be Euler's
# constant.
my ($class, $x, $base, @r);
# Don't objectify the base, since an undefined base, as in $x->blog() or
# $x->blog(undef) signals that the base is Euler's number.
# set up parameters
my ($class, $x, $base, @r) = (undef, @_);
# objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) {
($class, $x, $base, @r) = objectify(2, @_);
if (!ref($_[0]) && $_[0] =~ /^[A-Za-z]|::/) {
# E.g., Math::BigInt->blog(256, 2)
($class, $x, $base, @r) =
defined $_[2] ? objectify(2, @_) : objectify(1, @_);
} else {
# E.g., Math::BigInt::blog(256, 2) or $x->blog(2)
($class, $x, $base, @r) =
defined $_[1] ? objectify(2, @_) : objectify(1, @_);
}
return $x if $x->modify('blog');
......@@ -2718,16 +2723,131 @@ sub bfac {
}
sub bdfac {
# compute factorial number from $x, modify $x in place
# compute double factorial, modify $x in place
my ($class, $x, @r) = ref($_[0]) ? (undef, @_) : objectify(1, @_);
return $x if $x->modify('bdfac') || $x->{sign} eq '+inf'; # inf => inf
return $x->bnan() if $x->{sign} ne '+'; # NaN, <0 etc => NaN
Carp::croak("bdfac() requires a newer version of the $CALC library.")
unless $CALC->can('_dfac');
$x->{value} = $CALC->_dfac($x->{value});
$x->round(@r);
}
sub bfib {
# compute Fibonacci number(s)
my ($class, $x, @r) = objectify(1, @_);
Carp::croak("bfib() requires a newer version of the $CALC library.")
unless $CALC->can('_fib');
return $x if $x->modify('bfib');
# List context.
if (wantarray) {
return () if $x -> is_nan();
Carp::croak("bfib() can't return an infinitely long list of numbers")
if $x -> is_inf();
# Use the backend library to compute the first $x Fibonacci numbers.
my @values = $CALC->_fib($x->{value});
# Make objects out of them. The last element in the array is the
# invocand.
for (my $i = 0 ; $i < $#values ; ++ $i) {
my $fib = $class -> bzero();
$fib -> {value} = $values[$i];
$values[$i] = $fib;
}
$x -> {value} = $values[-1];
$values[-1] = $x;
# If negative, insert sign as appropriate.
if ($x -> is_neg()) {
for (my $i = 2 ; $i <= $#values ; $i += 2) {
$values[$i]{sign} = '-';
}
}
@values = map { $_ -> round(@r) } @values;
return @values;
}
# Scalar context.
else {
return $x if $x->modify('bdfac') || $x -> is_inf('+');
return $x->bnan() if $x -> is_nan() || $x -> is_inf('-');
$x->{sign} = $x -> is_neg() && $x -> is_even() ? '-' : '+';
$x->{value} = $CALC->_fib($x->{value});
return $x->round(@r);
}
}
sub blucas {
# compute Lucas number(s)
my ($class, $x, @r) = objectify(1, @_);
Carp::croak("blucas() requires a newer version of the $CALC library.")
unless $CALC->can('_lucas');
return $x if $x->modify('blucas');
# List context.
if (wantarray) {
return () if $x -> is_nan();
Carp::croak("blucas() can't return an infinitely long list of numbers")
if $x -> is_inf();
# Use the backend library to compute the first $x Lucas numbers.
my @values = $CALC->_lucas($x->{value});
# Make objects out of them. The last element in the array is the
# invocand.
for (my $i = 0 ; $i < $#values ; ++ $i) {
my $lucas = $class -> bzero();
$lucas -> {value} = $values[$i];
$values[$i] = $lucas;
}
$x -> {value} = $values[-1];
$values[-1] = $x;
# If negative, insert sign as appropriate.
if ($x -> is_neg()) {
for (my $i = 2 ; $i <= $#values ; $i += 2) {
$values[$i]{sign} = '-';
}
}
@values = map { $_ -> round(@r) } @values;
return @values;
}
# Scalar context.
else {
return $x if $x -> is_inf('+');
return $x->bnan() if $x -> is_nan() || $x -> is_inf('-');
$x->{sign} = $x -> is_neg() && $x -> is_even() ? '-' : '+';
$x->{value} = $CALC->_lucas($x->{value});
return $x->round(@r);
}
}
sub blsft {
# (BINT or num_str, BINT or num_str) return BINT
# compute x << y, base n, y >= 0
......@@ -3635,7 +3755,8 @@ sub objectify {
# Class->badd(Class->(1), 2); => classname x (scalar), ref x, scalar y
# Math::BigInt::badd(1, 2); => scalar x, scalar y
# A shortcut for the common case $x->unary_op():
# A shortcut for the common case $x->unary_op(), in which case the argument
# list is (0, $x) or (1, $x).
return (ref($_[1]), $_[1]) if @_ == 2 && ($_[0] || 0) == 1 && ref($_[1]);
......@@ -3648,7 +3769,6 @@ sub objectify {
# Get the number of arguments to objectify.
my $count = shift;
$count ||= @_;
# Initialize the output array.
......@@ -3658,17 +3778,18 @@ sub objectify {
# class name. Otherwise, if the first argument looks like a class name,
# then use that as our class name. Otherwise, use the default class name.
{
if (ref($a[0])) { # reference?
unshift @a, ref($a[0]);
last;
}
if ($a[0] =~ /^[A-Z].*::/) { # string with class name?
last;
}
unshift @a, $class; # default class name
my $class;
if (ref($a[0])) { # reference?
$class = ref($a[0]);
} elsif ($a[0] =~ /^[A-Z].*::/) { # string with class name?
$class = shift @a;
} else {
$class = __PACKAGE__; # default class name
}
$count ||= @a;
unshift @a, $class;
no strict 'refs';
# What we upgrade to, if anything.
......@@ -3686,12 +3807,6 @@ sub objectify {
for my $i (1 .. $count) {
# Don't do anything with undefs. This special treatment is necessary
# because blog() might have a second operand which is undef, to signify
# that the default Euler base should be used.
next unless defined $a[$i];
my $ref = ref $a[$i];
# Perl scalars are fed to the appropriate constructor.
......@@ -5177,6 +5292,74 @@ product of all positive, even integers up to and including C<$x>, i.e.,
2*4*6*...*$x. If C<$x> is an odd integer, returns the product of all positive,
odd integers, i.e., 1*3*5*...*$x.
=item bfib()
$F = $n->bfib(); # a single Fibonacci number
@F = $n->bfib(); # a list of Fibonacci numbers
In scalar context, returns a single Fibonacci number. In list context, returns
a list of Fibonacci numbers. The invocand is the last element in the output.
The Fibonacci sequence is defined by
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)
In list context, F(0) and F(n) is the first and last number in the output,
respectively. For example, if $n is 12, then C<< @F = $n->bfib() >> returns the
following values, F(0) to F(12):
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144
The sequence can also be extended to negative index n using the re-arranged
recurrence relation
F(n-2) = F(n) - F(n-1)
giving the bidirectional sequence
n -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
F(n) 13 -8 5 -3 2 -1 1 0 1 1 2 3 5 8 13
If $n is -12, the following values, F(0) to F(12), are returned:
0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144
=item blucas()
$F = $n->blucas(); # a single Lucas number
@F = $n->blucas(); # a list of Lucas numbers
In scalar context, returns a single Lucas number. In list context, returns a
list of Lucas numbers. The invocand is the last element in the output.
The Lucas sequence is defined by
L(0) = 2
L(1) = 1
L(n) = L(n-1) + L(n-2)
In list context, L(0) and L(n) is the first and last number in the output,
respectively. For example, if $n is 12, then C<< @L = $n->blucas() >> returns
the following values, L(0) to L(12):
2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322
The sequence can also be extended to negative index n using the re-arranged
recurrence relation
L(n-2) = L(n) - L(n-1)
giving the bidirectional sequence
n -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
L(n) 29 -18 11 -7 4 -3 1 2 1 3 4 7 11 18 29
If $n is -12, the following values, L(0) to L(-12), are returned:
2, 1, -3, 4, -7, 11, -18, 29, -47, 76, -123, 199, -322
=item brsft()
$x->brsft($n); # right shift $n places in base 2
......
......@@ -7,7 +7,7 @@ use warnings;
use Carp;
use Math::BigInt::Lib;
our $VERSION = '1.999808';
our $VERSION = '1.999811';
our @ISA = ('Math::BigInt::Lib');
......
......@@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;
our $VERSION = '1.999808';
our $VERSION = '1.999811';
package Math::BigInt;
......
......@@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;
our $VERSION = '1.999808';
our $VERSION = '1.999811';
use Carp;
......@@ -1405,6 +1405,100 @@ sub _lcm {
return $x;
}
sub _lucas {
my ($class, $n) = @_;
$n = $class -> _num($n) if ref $n;
# In list context, use lucas(n) = lucas(n-1) + lucas(n-2)
if (wantarray) {
my @y;
push @y, $class -> _two();
return @y if $n == 0;