Commit 19407e3b authored by Lucas Kanashiro's avatar Lucas Kanashiro

Imported Upstream version 1.999707

parent 4483dcf3
......@@ -1420,18 +1420,53 @@ The changes are now grouped by distribution.
2015-09-25 v1.999704 pjacklam
* objectify() in lib/Math/BigInt.pm now uses 'isa' not 'eq' to check object
relationship. This is necessary for correct handling of subclasses.
* objectify() in lib/Math/BigInt.pm now uses 'isa' not 'eq' to check object
relationship. This is necessary for correct handling of subclasses.
* objectify() in lib/Math/BigInt.pm no longer expects as_int(), as_number()
and as_float() to return objects, but allows them to return numbers
formatted as strings. This is used by some other modules on CPAN.
* objectify() in lib/Math/BigInt.pm no longer expects as_int(), as_number()
and as_float() to return objects, but allows them to return numbers
formatted as strings. This is used by some other modules on CPAN.
* Better documentation of as_int() and as_number() in lib/Math/BigInt.pm.
* Better documentation of as_int() and as_number() in lib/Math/BigInt.pm.
* Add documentation for as_float() in lib/Math/BigFloat.pm
* Add documentation for as_float() in lib/Math/BigFloat.pm
* Added test files t/objectify_mbf.t and t/objectify_mbi.t.
* Added test files t/objectify_mbf.t and t/objectify_mbi.t.
2015-10-26 v1.999705 pjacklam
* Avoid using "my" in a false conditional. See "Deprecated use of my() in
false conditional" in perldiag(1).
* Faster algorithm for bpi() when accuracy is >= 1000.
2015-10-28 v1.999706 pjacklam
* Corrected release date of v1.999705 in CHANGES.
* Added code and tests for numify() on non-finite objects.
2015-10-29 v1.999707 pjacklam
* Added dependency on Math::Complex 1.39 for Math::Complex::Inf(), which is
used for numifying infinity.
* Updated author information.
* Updated information in the file README.
* Removed the files INSTALL and LICENSE as this information is already covered
in the file README.
* Enable 'use warnings' in all modules. We require a Perl newer than 5.6.0
anyway.
* Replace 'use vars ...' with 'our ...'. We require a Perl newer than 5.6.0
anyway.
* Avoid indirect object syntax in documentation.
* Moved 'Test::More' from 'build_requires' to 'test_requires' in Makefile.PL.
Please send us test-reports, your experiences with this and your ideas - we love
to hear about our work!
......
Rewrite project of Math::Big*
(C) Copyright ..--- ----- ----- .---- - ..--- by - . .-.. ... .-.-.-
Contains new version of Math::BigInt and Math::BigFloat as they are in the
Perl core from v5.8.0 onwards.
This rewritten version is mainly compatible, minus some bugfixes, and more
features and speed.
To test, unzip & untar package, then run
perl Makefile.PL
make
make test
make install # as root
These modules should be installed automatically into the Perl core, and not
into site-perl. You can check whether you get the old or new versions by doing
this:
perl -MMath::BigInt -le 'print "v$Math::BigInt::VERSION"'
If it prints undef or v0.01 you still got the old version. Delete the files
from the Perl core installation path manually, and make sure that you
delete all old versions, then try again to print the version from above.
For a quick reference on what has changed from the old versions, please see
CHANGES. HISTORY brings you a detailed history log of the rewrite.
In ./examples are some basic example scripts.
More information including HTMLified help and benchmark results are
available under:
http://bloodgate.com/perl/
Please send me test-reports, your experiences with this and your ideas - I love
to hear about my work!
Tels <http://bloodgate.com/>
......@@ -15,7 +15,6 @@ inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
INSTALL
lib/Math/BigFloat.pm
lib/Math/BigInt.pm
lib/Math/BigInt/Calc.pm
......
{
"abstract" : "Arbitrary size integer/float math package",
"author" : [
"Original code by Mark Biggar, overloaded interface by Ilya Zakharevich., Tels <nospam-abuse@bloodgate.com>"
"=over 4, Peter John Acklam <pjacklam@online.no>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005",
......@@ -33,11 +33,13 @@
},
"runtime" : {
"requires" : {
"Math::Complex" : "1.39",
"Test::More" : "0.62",
"perl" : "5.006002"
}
}
},
"release_status" : "stable",
"version" : "1.999704",
"version" : "1.999707",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
---
abstract: 'Arbitrary size integer/float math package'
author:
- 'Original code by Mark Biggar, overloaded interface by Ilya Zakharevich., Tels <nospam-abuse@bloodgate.com>'
- '=over 4, Peter John Acklam <pjacklam@online.no>'
build_requires:
ExtUtils::MakeMaker: '6.59'
Test::More: '0.62'
......@@ -19,6 +19,8 @@ no_index:
- t
- inc
requires:
Math::Complex: '1.39'
Test::More: '0.62'
perl: '5.006002'
version: '1.999704'
version: '1.999707'
x_serialization_backend: 'CPAN::Meta::YAML version 0.016'
......@@ -12,15 +12,15 @@ name 'Math-BigInt';
all_from 'lib/Math/BigInt.pm';
# Required versions.
requires 'perl' => 5.006002;
build_requires 'Test::More' => 0.62;
requires 'perl' => 5.006002;
requires 'Math::Complex' => 1.39,
test_requires 'Test::More' => 0.62;
install_as_core();
license 'perl';
author 'Tels <nospam-abuse@bloodgate.com>';
author 'Peter John Acklam <pjacklam@online.no>';
# Do not index these
no_index directory => 'examples';
......
Rewrite project of Math::BigInt, Math::BigFloat.
Math-BigInt
(C) Copyright ..--- ----- ----- .---- - ..--- by - . .-.. ... .-.-.-
Math::BigInt and Math::BigFloat are modules for arbitrary precision
arithmetic.
This package contains completely rewritten versions of Math::BigInt and
Math::BigFloat.
INSTALLATION
To test, unzip & untar package, then run
To install this module, unpack the distribution file, and run the following
commands:
perl Makefile.PL
make
make test
make install
perl Makefile.PL
make
make test
make install
See also ./examples for some example scripts.
SUPPORT AND DOCUMENTATION
See INSTALL for detailed help on installing these modules.
After installing, you can find documentation for these modules with the
perldoc command.
You can look on CPAN (http://search.cpan.org/) for modules that replace the
core math routines of Math::BigInt (look for Math::BigInt::BitVect, f.i.).
perldoc Math::BigInt
perldoc Math::BigFloat
More information including HTMLified help are available under:
You can also look for information at:
http://bloodgate.com/perl/ # project homepage
http://bloodgate.com/perl/benchmarks.html # benchmarks
RT, CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-BigInt
Please send me test-reports, your experiences with this and your ideas - I love
to hear about my work!
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Math-BigInt
Tels <http://bloodgate.com/>
CPAN Ratings
http://cpanratings.perl.org/d/Math-BigInt
Search CPAN
http://search.cpan.org/dist/Math-BigInt
COPYRIGHT AND LICENCE
Copyright 2007-2010 Peter John Acklam <pjacklam@online.no>
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
......@@ -16,19 +16,18 @@ Hash: SHA1
SHA1 f6ef98e8f3f6a4f670d569f279ef5a3c05c16d0c BENCHMARK
SHA1 d681b992c9e027633a59fbd52530805ee4e1621c BUGS
SHA1 8ea50abf4bd86783767a277d9578f06e78fc7e56 CHANGES
SHA1 e1631812ed199c52be5185306d15e4bb4593891c CHANGES
SHA1 f27c8bd98e754f96c9825fa6ce9f1244c93bdbe6 CREDITS
SHA1 bc2db74538d3acd53f71b5512a144fe18c253ecd GOALS
SHA1 fe61299e80a1dca48fbaa33f0869e3238ec07c70 HISTORY
SHA1 c42565ad26cdf91502bacf19a4f7080e63c51fe2 INSTALL
SHA1 d6a6c30ee6d9ba6b9afab8bbf6a25e1b23c744e0 LICENSE
SHA1 183f44987a5dfba10182b1b89f1f92647e388a5f MANIFEST
SHA1 e717092a11b1e42a0a7b340c68e75fa84b8a68b8 MANIFEST
SHA1 86df44fbe1ea7a68897113f0e327d0f0c25b91e3 MANIFEST.SKIP
SHA1 27f71484021cedc3ac0c8d0776279f88610ba004 META.json
SHA1 926b03441e37ae13d3dc24a081fda22d2990b7c5 META.yml
SHA1 ae1e2767f1988a537d4a64fc84a07587cbca2ef5 Makefile.PL
SHA1 20885b2d7e7695e64a9164d2b557a3f728de8a84 META.json
SHA1 0b7fa178b5c3b96317f466af4de50517da24442d META.yml
SHA1 a3da36a5af3eedcf0461fea65319bc69e8ff69ee Makefile.PL
SHA1 4e2191d1724e699862efc5350f480c8e02755112 NEW
SHA1 481f5827752d2100914db1eaeb60bf0bbd13529e README
SHA1 a1c4ab669fbeff68e7965c1bc3ced16d17a9f2f5 README
SHA1 f1500916b488220b707bc10a0388d7dbcfd52e99 TODO
SHA1 c2bbe82659480de8710b9e64a62d47b64dddd2d2 examples/1000.txt
SHA1 fe55e27b4791656d36a6c9548280746de7003be5 examples/bigprimes.pl
......@@ -41,10 +40,10 @@ SHA1 76efdca3603159e0ae0e18f19fe72a0211a69529 inc/Module/Install/Makefile.pm
SHA1 2e33e87882d60db3913da6284dd5295e5315e18a inc/Module/Install/Metadata.pm
SHA1 c830b819e61bda5eca077c6291293bba61b3b9f2 inc/Module/Install/Win32.pm
SHA1 cb52b9d6f88d512d448a6f35ed0af0d1201a134b inc/Module/Install/WriteAll.pm
SHA1 2b4a6499b7f55d6bb33cb942bdf83853d094b404 lib/Math/BigFloat.pm
SHA1 b11a534087024e20f724475d2648d259fc03eb1b lib/Math/BigInt.pm
SHA1 964d54429022e659b55e1b236041bccaa0fc74ba lib/Math/BigInt/Calc.pm
SHA1 70d46d848ba40caa86372df20efd3fac47d0e29c lib/Math/BigInt/CalcEmu.pm
SHA1 1914eb138f472f8fc090078c7b44259b000e3069 lib/Math/BigFloat.pm
SHA1 5c79f8bb3acd0d867409ee39b2a9c32ae70e1ca6 lib/Math/BigInt.pm
SHA1 486fc42db97cd2a05ea4c845e0bae2733d3d2896 lib/Math/BigInt/Calc.pm
SHA1 56ceeb7353bf171e53dc2f8bb662a20c9f530f8b lib/Math/BigInt/CalcEmu.pm
SHA1 385cc7ed3bf3e6290640b9880445ca9a3dea629e t/00sig.t
SHA1 4463fdcebb8421cc2e63f87d678adb47856bf58c t/01load.t
SHA1 b2ed9206ca5b69ec3b8bbf850bf4b6dfde518e7e t/02pod.t
......@@ -55,14 +54,14 @@ SHA1 62deb0b9e3bf94aaf12745207efa3d858f3b878e t/Math/BigInt/Scalar.pm
SHA1 27c1738a064e7f7bf91c762d411af447847c331c t/Math/BigInt/Subclass.pm
SHA1 a2014803baec5dbef46235f83411f76efa0efea7 t/_e_math.t
SHA1 0e725849a20e80bb1da796a7be40b69a958c8313 t/alias.inc
SHA1 544c9c718179ef5ea77766c5a6d0c1a393609f52 t/bare_mbf.t
SHA1 9f0d228c71dd1b49ea6de9ea9f67dcf30d3edccc t/bare_mbf.t
SHA1 633a5d1446321301fe2fbf8d440111ad62ffddfb t/bare_mbi.t
SHA1 97fb1db80aeb4ab007e2260d35329e149edf5e05 t/bare_mif.t
SHA1 333a425247b4e276696210a6322b815a0f55f5ab t/big_pi_e.t
SHA1 96dbc74d7c77cf3bf70dd77d7b21fbce44c630b2 t/bigfltpm.inc
SHA1 965f40208f73d9e51277d309310763d8336a0f1b t/bigfltpm.t
SHA1 9bc755bda3026da5300d62e88bd797ead7366348 t/bigfltpm.inc
SHA1 10f64067004036704aa30c0e40da7a8d83eef708 t/bigfltpm.t
SHA1 b3ceebc429c05bce95347575d28348306dbcfcc8 t/bigintc.t
SHA1 ea7f75ed9aa5feae4b1f32ea7a7c2d909f6b68c3 t/bigintpm.inc
SHA1 7954255fd6b3a4a09b6e47c98a1ed79d40a49e22 t/bigintpm.inc
SHA1 ba3d855434e4fea04c22bdd54076ed9706a79d5f t/bigintpm.t
SHA1 cb07d195c20eb306088eeacccc2c7475f267446c t/bigints.t
SHA1 0e505ab877fb41505d683163ad3f09027f9eef35 t/biglog.t
......@@ -96,7 +95,7 @@ SHA1 1bbe72733abd2f580f94b6a147672f7671260149 t/require.t
SHA1 ad6cc6fe4bb93ae78db4eb7dcb96c95024b963d2 t/round.t
SHA1 8201ea0035861736224992039bcc01d5bd72b778 t/rt-16221.t
SHA1 9d51def046889bf20c6ac2a278f9b3f5f8e36025 t/sub_ali.t
SHA1 d03a42bc484dd3517979c1a3668e38d5c5d26367 t/sub_mbf.t
SHA1 3e85cad277cb8490910285f8541a43bda6623cbb t/sub_mbf.t
SHA1 94d13e2f3807f37b1489f7540fa46995f9f78d8e t/sub_mbi.t
SHA1 a9d994551c5ca127c11f5cdd1d8df1d93972c72c t/sub_mif.t
SHA1 22c563a6879c94ce7c8eb72c645f2e374837c34e t/trap.t
......@@ -110,15 +109,15 @@ SHA1 4959257dd52935cdfd17b132e11bcdb4e37752e9 t/use_lib2.t
SHA1 29606835c9d63a19075003429b00947b922ef144 t/use_lib3.t
SHA1 a5cc44a7e485828791696b2b27925e0d2855f883 t/use_lib4.t
SHA1 0c5f496ed66b02d0e118763c91862d84e3fb5629 t/use_mbfw.t
SHA1 34e18efc281d6538ba91742afa82d50c3b4434ad t/with_sub.t
SHA1 01c5bfaa17310e1cea23ad46eacfe1613c291cac t/with_sub.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJWBUoXAAoJEGcmPl2fr166VgEIANnEsYBpwPSRz2gQhWKYyzAs
2c23b3RmyMA3VmnapfjRCpIZkFEmqHo0Pl/QwDBlNN00RN00cZHdwJ9s8dhNSZyJ
rE+Xdi0kc/I6D4EVXSf25AqH7VymZRoJzkX+IPqj7xFw7HmdIKraMwXY7CLsN+Fm
WhcnX6Pbr6D5+C6tNX6yLmjZyTnl7CaqO5Beq49OH23nHTzY2247rowumoH1PpTu
XIOArzhazregnPcb4sV6boqnZtFwosOGZmr8cWT82HGGyFhYhh1rokpYr/08RecI
RBdipu8M2qsbsKTHl0mAhc0AYXp0p8gZW1zGnMX55JH21h9uXZlJw3iLnhYvGTY=
=w70R
iQEcBAEBAgAGBQJWMj6TAAoJEGcmPl2fr166dAQH/RfhE0u3Rl7TxLyTDikGrPX2
xL21DLsagbLKn705iFqxRiDRzI6lQ/cQEaI37wDeAee6IrABAZW5daFKGJgAv83q
3K+oDFnNfiPHQvmJdlbkvGJw2Xyi8HPrKwDbUifXxPblMPiHVzJT/84o68FYwqrq
CcpkRQ+FgoraH+zW4k9m9FLfTCNkgCioP/WqzZmVp6aRcyyiOdMWQlZQauyKMhSk
YFlcPHaRvJJ8AUS6ktAsX0E+qM7CZo3oINMO1CqzgYZlxZTXklGSKMwA69ymVPMa
C5s1uZM/cjnyK11BVclqoWy/Xyuswagud1WBs2wV7ybTrS4rPMOy20Ye+Musv/w=
=52Ia
-----END PGP SIGNATURE-----
......@@ -12,17 +12,20 @@ package Math::BigFloat;
# _a : accuracy
# _p : precision
$VERSION = '1.999704';
require 5.006002;
use 5.006002;
use strict;
use warnings;
our $VERSION = '1.999707';
require Exporter;
@ISA = qw/Math::BigInt/;
@EXPORT_OK = qw/bpi/;
our @ISA = qw/Math::BigInt/;
our @EXPORT_OK = qw/bpi/;
use strict;
# $_trap_inf/$_trap_nan are internal and should never be accessed from outside
use vars qw/$AUTOLOAD $accuracy $precision $div_scale $round_mode $rnd_mode
$upgrade $downgrade $_trap_nan $_trap_inf/;
our ($AUTOLOAD, $accuracy, $precision, $div_scale, $round_mode, $rnd_mode,
$upgrade, $downgrade, $_trap_nan, $_trap_inf);
my $class = "Math::BigFloat";
use overload
......@@ -437,10 +440,23 @@ sub bsstr
sub numify
{
# Convert a Perl scalar number from a BigFloat object.
# Create a string and let Perl's atoi()/atof() handle the rest.
# Make a Perl scalar number from a Math::BigFloat object.
my ($self,$x) = ref($_[0]) ? (undef,$_[0]) : objectify(1,@_);
return 0 + $x->bsstr();
if ($x -> is_nan()) {
require Math::Complex;
my $inf = Math::Complex::Inf();
return $inf - $inf;
}
if ($x -> is_inf()) {
require Math::Complex;
my $inf = Math::Complex::Inf();
return $x -> is_negative() ? -$inf : $inf;
}
# Create a string and let Perl's atoi()/atof() handle the rest.
return 0 + $x -> bsstr();
}
##############################################################################
......@@ -1302,7 +1318,7 @@ sub _log
$over->bmul($u);
$factor = $self->new(3); $f = $self->new(2);
my $steps = 0 if DEBUG;
my $steps = 0;
$limit = $self->new("1E-". ($scale-1));
while (3 < 5)
{
......@@ -2811,48 +2827,77 @@ sub bpi
my $fallback = defined $n ? 0 : 1;
$n = 40 if !defined $n || $n < 1;
# after 黃見利 (Hwang Chien-Lih) (1997)
# pi/4 = 183 * atan(1/239) + 32 * atan(1/1023) – 68 * atan(1/5832)
# + 12 * atan(1/110443) - 12 * atan(1/4841182) - 100 * atan(1/6826318)
# a few more to prevent rounding errors
$n += 4;
my ($a,$b) = $self->_atan_inv( $MBI->_new(239),$n);
my ($c,$d) = $self->_atan_inv( $MBI->_new(1023),$n);
my ($e,$f) = $self->_atan_inv( $MBI->_new(5832),$n);
my ($g,$h) = $self->_atan_inv( $MBI->_new(110443),$n);
my ($i,$j) = $self->_atan_inv( $MBI->_new(4841182),$n);
my ($k,$l) = $self->_atan_inv( $MBI->_new(6826318),$n);
$MBI->_mul($a, $MBI->_new(732));
$MBI->_mul($c, $MBI->_new(128));
$MBI->_mul($e, $MBI->_new(272));
$MBI->_mul($g, $MBI->_new(48));
$MBI->_mul($i, $MBI->_new(48));
$MBI->_mul($k, $MBI->_new(400));
my $x = $self->bone(); $x->{_m} = $a; my $x_d = $self->bone(); $x_d->{_m} = $b;
my $y = $self->bone(); $y->{_m} = $c; my $y_d = $self->bone(); $y_d->{_m} = $d;
my $z = $self->bone(); $z->{_m} = $e; my $z_d = $self->bone(); $z_d->{_m} = $f;
my $u = $self->bone(); $u->{_m} = $g; my $u_d = $self->bone(); $u_d->{_m} = $h;
my $v = $self->bone(); $v->{_m} = $i; my $v_d = $self->bone(); $v_d->{_m} = $j;
my $w = $self->bone(); $w->{_m} = $k; my $w_d = $self->bone(); $w_d->{_m} = $l;
$x->bdiv($x_d, $n);
$y->bdiv($y_d, $n);
$z->bdiv($z_d, $n);
$u->bdiv($u_d, $n);
$v->bdiv($v_d, $n);
$w->bdiv($w_d, $n);
delete $x->{_a}; delete $y->{_a}; delete $z->{_a};
delete $u->{_a}; delete $v->{_a}; delete $w->{_a};
$x->badd($y)->bsub($z)->badd($u)->bsub($v)->bsub($w);
$x->bround($n-4);
delete $x->{_a} if $fallback == 1;
$x;
if ($n < 1000) {
# after 黃見利 (Hwang Chien-Lih) (1997)
# pi/4 = 183 * atan(1/239) + 32 * atan(1/1023) – 68 * atan(1/5832)
# + 12 * atan(1/110443) - 12 * atan(1/4841182) - 100 * atan(1/6826318)
# Use a few more digits in the intermediate computations.
my $nextra = $n < 800 ? 4 : 5;
$n += $nextra;
my ($a,$b) = $self->_atan_inv( $MBI->_new(239),$n);
my ($c,$d) = $self->_atan_inv( $MBI->_new(1023),$n);
my ($e,$f) = $self->_atan_inv( $MBI->_new(5832),$n);
my ($g,$h) = $self->_atan_inv( $MBI->_new(110443),$n);
my ($i,$j) = $self->_atan_inv( $MBI->_new(4841182),$n);
my ($k,$l) = $self->_atan_inv( $MBI->_new(6826318),$n);
$MBI->_mul($a, $MBI->_new(732));
$MBI->_mul($c, $MBI->_new(128));
$MBI->_mul($e, $MBI->_new(272));
$MBI->_mul($g, $MBI->_new(48));
$MBI->_mul($i, $MBI->_new(48));
$MBI->_mul($k, $MBI->_new(400));
my $x = $self->bone(); $x->{_m} = $a; my $x_d = $self->bone(); $x_d->{_m} = $b;
my $y = $self->bone(); $y->{_m} = $c; my $y_d = $self->bone(); $y_d->{_m} = $d;
my $z = $self->bone(); $z->{_m} = $e; my $z_d = $self->bone(); $z_d->{_m} = $f;
my $u = $self->bone(); $u->{_m} = $g; my $u_d = $self->bone(); $u_d->{_m} = $h;
my $v = $self->bone(); $v->{_m} = $i; my $v_d = $self->bone(); $v_d->{_m} = $j;
my $w = $self->bone(); $w->{_m} = $k; my $w_d = $self->bone(); $w_d->{_m} = $l;
$x->bdiv($x_d, $n);
$y->bdiv($y_d, $n);
$z->bdiv($z_d, $n);
$u->bdiv($u_d, $n);
$v->bdiv($v_d, $n);
$w->bdiv($w_d, $n);
delete $x->{_a}; delete $y->{_a}; delete $z->{_a};
delete $u->{_a}; delete $v->{_a}; delete $w->{_a};
$x->badd($y)->bsub($z)->badd($u)->bsub($v)->bsub($w);
$x->bround($n-$nextra);
delete $x->{_a} if $fallback == 1;
$x;
} else {
# For large accuracy, the arctan formulas become very inefficient with
# Math::BigFloat. Switch to Brent-Salamin (aka AGM or Gauss-Legendre).
# Use a few more digits in the intermediate computations.
my $nextra = 8;
$HALF = $self -> new($HALF) unless ref($HALF);
my ($an, $bn, $tn, $pn) = ($self -> bone, $HALF -> copy -> bsqrt($n),
$HALF -> copy -> bmul($HALF), $self -> bone);
while ($pn < $n) {
my $prev_an = $an -> copy;
$an -> badd($bn) -> bmul($HALF, $n);
$bn -> bmul($prev_an) -> bsqrt($n);
$prev_an -> bsub($an);
$tn -> bsub($pn * $prev_an * $prev_an);
$pn -> badd($pn);
}
$an -> badd($bn);
$an -> bmul($an, $n) -> bdiv(4 * $tn, $n - $nextra);
delete $an -> {_a} if $fallback == 1;
return $an;
}
}
sub bcos
{
......@@ -4097,7 +4142,7 @@ Math::BigFloat - Arbitrary size floating point math package
All operators (including basic math operations) are overloaded if you
declare your big floating point numbers as
$i = new Math::BigFloat '12_3.456_789_123_456_789E-2';
$i = Math::BigFloat -> new('12_3.456_789_123_456_789E-2');
Operations with overloaded operators preserve the arguments, which is
exactly what you expect.
......@@ -4742,8 +4787,24 @@ because they solve the autoupgrading/downgrading issue, at least partly.
=head1 AUTHORS
Mark Biggar, overloaded interface by Ilya Zakharevich.
Completely rewritten by Tels L<http://bloodgate.com> in 2001 - 2006, and still
at it in 2007.
=over 4
=item *
Mark Biggar, overloaded interface by Ilya Zakharevich, 1996-2001.
=item *
Completely rewritten by Tels L<http://bloodgate.com> in 2001-2008.
=item *
Florian Ragwitz L<flora@cpan.org>, 2010.
=item *
Peter John Acklam, L<pjacklam@online.no>, 2011-.
=back
=cut
......@@ -15,19 +15,21 @@ package Math::BigInt;
# Remember not to take shortcuts ala $xs = $x->{value}; $CALC->foo($xs); since
# underlying lib might change the reference!
my $class = "Math::BigInt";
use 5.006002;
use strict;
use warnings;
$VERSION = '1.999704';
our $VERSION = '1.999707';
@ISA = qw(Exporter);
@EXPORT_OK = qw(objectify bgcd blcm);
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(objectify bgcd blcm);
# _trap_inf and _trap_nan are internal and should never be accessed from the
# outside
use vars qw/$round_mode $accuracy $precision $div_scale $rnd_mode
$upgrade $downgrade $_trap_nan $_trap_inf/;
use strict;
our ($round_mode, $accuracy, $precision, $div_scale, $rnd_mode,
$upgrade, $downgrade, $_trap_nan, $_trap_inf);
my $class = "Math::BigInt";
# Inside overload, the first arg is always an object. If the original code had
# it reversed (like $x = 2 * $y), then the third parameter is true.
......@@ -846,13 +848,23 @@ sub bstr
sub numify
{
# Make a "normal" scalar from a BigInt object
# Make a Perl scalar number from a Math::BigInt object.
my $x = shift; $x = $class->new($x) unless ref $x;
return $x->bstr() if $x->{sign} !~ /^[+-]$/;
my $num = $CALC->_num($x->{value});
return -$num if $x->{sign} eq '-';
$num;
if ($x -> is_nan()) {
require Math::Complex;
my $inf = Math::Complex::Inf();
return $inf - $inf;
}
if ($x -> is_inf()) {
require Math::Complex;
my $inf = Math::Complex::Inf();
return $x -> is_negative() ? -$inf : $inf;
}
my $num = 0 + $CALC->_num($x->{value});
return $x->{sign} eq '-' ? -$num : $num;
}
##############################################################################
......@@ -3631,7 +3643,7 @@ Math::BigInt - Arbitrary size integer/float math package
All operators (including basic math operations) are overloaded if you
declare your big integers as
$i = new Math::BigInt '123_456_789_123_456_789';
$i = Math::BigInt -> new('123_456_789_123_456_789');
Operations with overloaded operators preserve the arguments which is
exactly what you expect.
......@@ -5182,13 +5194,20 @@ is in effect, they will always hand up their work:
=item bexp()
=back
=item bpi()
Beware: This list is not complete.
=item bcos()
=item bsin()
=item batan2()
=item batan()
=back
All other methods upgrade themselves only when one (or all) of their
arguments are of the class mentioned in $upgrade (This might change in later
versions to a more sophisticated scheme):
arguments are of the class mentioned in $upgrade.
=head1 EXPORTS
......@@ -5225,8 +5244,8 @@ So, the following examples will now work all as expected:
use Test::More tests => 1;
use Math::BigInt;
my $x = new Math::BigInt 3*3;
my $y = new Math::BigInt 3*3;
my $x = Math::BigInt -> new(3*3);
my $y = Math::BigInt -> new(3*3);
is ($x,3*3, 'multiplication');
print "$x eq 9" if $x eq $y;
......@@ -5590,9 +5609,25 @@ because they solve the autoupgrading/downgrading issue, at least partly.
=head1 AUTHORS
Original code by Mark Biggar, overloaded interface by Ilya Zakharevich.
Completely rewritten by Tels http://bloodgate.com in late 2000, 2001 - 2006
and still at it in 2007.
=over 4
=item *
Mark Biggar, overloaded interface by Ilya Zakharevich, 1996-2001.
=item *
Completely rewritten by Tels L<http://bloodgate.com> in 2001-2008.
=item *
Florian Ragwitz L<flora@cpan.org>, 2010.
=item *
Peter John Acklam, L<pjacklam@online.no>, 2011-.
=back
Many people contributed in one or more ways to the final beast, see the file
CREDITS for an (incomplete) list. If you miss your name, please drop me a
......
......@@ -2,9 +2,9 @@ package Math::BigInt::Calc;
use 5.006002;
use strict;
# use warnings; # do not use warnings for older Perls
use warnings;
our $VERSION = '1.999704';
our $VERSION = '1.999707';
# Package to store unsigned big integers in decimal and do math with them
......
......@@ -2,10 +2,9 @@ package Math::BigInt::CalcEmu;
use 5.006002;
use strict;
# use warnings; # do not use warnings for older Perls
use vars qw/$VERSION/;
use warnings;
$VERSION = '1.999704';
our $VERSION = '1.999707';
package Math::BigInt;
......
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2360;
use Test::More tests => 2363;
BEGIN { unshift @INC, 't'; }
......
......@@ -268,6 +268,17 @@ like($class->new("12345e67")->numify(), qr/^1\.2345e\+?0*71$/);
like($class->new("1e-9999")->numify(), qr/^\+?0$/); # underflow
unlike($class->new("1e9999")->numify(), qr/^1(\.0*)?e\+?9+$/); # overflow
###############################################################################
# Check numify on non-finite objects.
{
my $inf = 1e99 ** 1e99;
my $nan = $inf - $inf;
is($class -> binf("+") -> numify(), $inf, "numify of +Inf");
is($class -> binf("-") -> numify(), -$inf, "numify of -Inf");
is($class -> bnan() -> numify(), $nan, "numify of NaN");
}
###############################################################################
# fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt()
# correctly modifies $x
......
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2360
use Test::More tests => 2363
+ 5; # own tests
......
......@@ -519,6 +519,17 @@ $x = 8 - $x; # 5 - 8 instead of 8 - 5
is ($x,-3);
is (ref($x),'Math::Foo');
###############################################################################