Commit 51e3bd98 authored by gregor herrmann's avatar gregor herrmann

Imported Upstream version 1.999703

parent d9c5e2a0
......@@ -9,7 +9,6 @@ The file NEW lists only the changes for the latest version.
##############################################################################
Math::BigInt::Calc:
2001-07-09 v0.06 Tels
* first release
......@@ -1390,6 +1389,35 @@ The changes are now grouped by distribution.
Math-BigInt distribution and the backend distributions are as few and as
small as possible. This makes for easier release management.
2015-09-17 v1.999702 pjacklam
* The overloaded log() is a unary operator, so don't pass additional
arguments.
* Fix blog() so the cases $x->blog() and $x->blog(undef) work correctly. An
undefined base means that blog() should use base e (Euler's number).
* Both CORE::log() and other mathematical software returns inf for log(inf),
so we do the same.
* Add tests for log() as well as templates for future tests of the other
overloadable functions.
* Improve descriptions of a few tests.
2015-09-21 v1.999703 pjacklam
* Fix blog() in Math::BigInt and Math::BigFloat to work correctly regardless
of the base.
* Correct existing tests in bigintpm.inc and bigfltpm.inc.
* Update test plans (number of tests) in t/bare_mbi.t, t/bigintpm.t, and
t/sub_mbi.t.
* Add test files t/blog-mbf.t and t/blog-mbi.t for better testing of the
blog() methods.
Please send us test-reports, your experiences with this and your ideas - we love
to hear about our work!
......
......@@ -44,6 +44,8 @@ t/bigintpm.t
t/bigints.t
t/biglog.t
t/bigroot.t
t/blog-mbf.t
t/blog-mbi.t
t/calling.t
t/config.t
t/const_mbf.t
......
......@@ -4,7 +4,7 @@
"Original code by Mark Biggar, overloaded interface by Ilya Zakharevich., Tels <nospam-abuse@bloodgate.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150005",
"generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005",
"license" : [
"perl_5"
],
......@@ -38,6 +38,6 @@
}
},
"release_status" : "stable",
"version" : "1.999701",
"version" : "1.999703",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
......@@ -8,7 +8,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150005'
generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
......@@ -20,5 +20,5 @@ no_index:
- inc
requires:
perl: '5.006002'
version: '1.999701'
version: '1.999703'
x_serialization_backend: 'CPAN::Meta::YAML version 0.016'
......@@ -16,16 +16,16 @@ Hash: SHA1
SHA1 f6ef98e8f3f6a4f670d569f279ef5a3c05c16d0c BENCHMARK
SHA1 d681b992c9e027633a59fbd52530805ee4e1621c BUGS
SHA1 0815a28c08ef29d983d21a6c7683c8c2b0d803e1 CHANGES
SHA1 6b566f5d8c537a75d173e1845d330a020b06ddab CHANGES
SHA1 f27c8bd98e754f96c9825fa6ce9f1244c93bdbe6 CREDITS
SHA1 bc2db74538d3acd53f71b5512a144fe18c253ecd GOALS
SHA1 fe61299e80a1dca48fbaa33f0869e3238ec07c70 HISTORY
SHA1 c42565ad26cdf91502bacf19a4f7080e63c51fe2 INSTALL
SHA1 d6a6c30ee6d9ba6b9afab8bbf6a25e1b23c744e0 LICENSE
SHA1 43408348b400ef1d910a18feab394817e343cc86 MANIFEST
SHA1 8f6a77cdcfede79a3fcf27549b2b8739eaefbfe8 MANIFEST
SHA1 86df44fbe1ea7a68897113f0e327d0f0c25b91e3 MANIFEST.SKIP
SHA1 d2c249bd0aa356187e6ad4326be5879dd0f83d1c META.json
SHA1 caefe2c8385d8be85408dc56b2c29cede24e3e17 META.yml
SHA1 43cf33ae05d036694ebfe2987e31217140278c9e META.json
SHA1 3cec127e47b24f6b3b0a21c8a6fc67aec2f3916a META.yml
SHA1 ae1e2767f1988a537d4a64fc84a07587cbca2ef5 Makefile.PL
SHA1 4e2191d1724e699862efc5350f480c8e02755112 NEW
SHA1 481f5827752d2100914db1eaeb60bf0bbd13529e README
......@@ -41,10 +41,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 bff33aecc126b34d7c2461f8c6ceee4bdabf428d lib/Math/BigFloat.pm
SHA1 981073b6c2b63068f5dee95608b1d14c837af5f7 lib/Math/BigInt.pm
SHA1 5e0a467afb8bfb66938252a2aa055b1cc343d728 lib/Math/BigInt/Calc.pm
SHA1 a5956e02f12e77650bc984f806be1172cab9b278 lib/Math/BigInt/CalcEmu.pm
SHA1 d69e58dac458d7bd76c7fb6182d50e7005fcca6d lib/Math/BigFloat.pm
SHA1 7bc1a3b537261121d93d275431bd86c45c0c6e5e lib/Math/BigInt.pm
SHA1 92b2144f0032d651cf1e7d3b37a82b01010febac lib/Math/BigInt/Calc.pm
SHA1 193c0c6d9b83e783b8071b8bbeee3f5bc0dcfddd lib/Math/BigInt/CalcEmu.pm
SHA1 385cc7ed3bf3e6290640b9880445ca9a3dea629e t/00sig.t
SHA1 4463fdcebb8421cc2e63f87d678adb47856bf58c t/01load.t
SHA1 b2ed9206ca5b69ec3b8bbf850bf4b6dfde518e7e t/02pod.t
......@@ -55,18 +55,20 @@ 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 c46706c4d6e75f1be26c938f8de19ca5990c672f t/bare_mbf.t
SHA1 4f40065bfe169022be4742991d4f28da17b65bfd t/bare_mbi.t
SHA1 544c9c718179ef5ea77766c5a6d0c1a393609f52 t/bare_mbf.t
SHA1 633a5d1446321301fe2fbf8d440111ad62ffddfb t/bare_mbi.t
SHA1 97fb1db80aeb4ab007e2260d35329e149edf5e05 t/bare_mif.t
SHA1 333a425247b4e276696210a6322b815a0f55f5ab t/big_pi_e.t
SHA1 d0a7c7c8852762abd7f962d26d72f2f8956f946d t/bigfltpm.inc
SHA1 2feb8161766c7a9427341307ab778f6eccbab21e t/bigfltpm.t
SHA1 96dbc74d7c77cf3bf70dd77d7b21fbce44c630b2 t/bigfltpm.inc
SHA1 965f40208f73d9e51277d309310763d8336a0f1b t/bigfltpm.t
SHA1 b3ceebc429c05bce95347575d28348306dbcfcc8 t/bigintc.t
SHA1 9fcc5a0c645880be1dc2083dc623de14f6b476d9 t/bigintpm.inc
SHA1 c5f14cee5968dea1b2871f2210a7be1a6a905e8c t/bigintpm.t
SHA1 ea7f75ed9aa5feae4b1f32ea7a7c2d909f6b68c3 t/bigintpm.inc
SHA1 ba3d855434e4fea04c22bdd54076ed9706a79d5f t/bigintpm.t
SHA1 cb07d195c20eb306088eeacccc2c7475f267446c t/bigints.t
SHA1 4e27fc0056d6455d278c0d38f5fe7f3c9a57fbe8 t/biglog.t
SHA1 0e505ab877fb41505d683163ad3f09027f9eef35 t/biglog.t
SHA1 b1aa233c07e7988ef67c9f527c9dc67b46d0a6fc t/bigroot.t
SHA1 01e72c0c34468a0c135c4bfc7e69a3274ca0a368 t/blog-mbf.t
SHA1 6e093e61e67395b85dc64911ce4e554d8a8f23dc t/blog-mbi.t
SHA1 2ed03baf88a7d868706605bada7874123f99eded t/calling.t
SHA1 c1f7b6840e772f2b6d4f8dbea4c28aaa675c9b17 t/config.t
SHA1 7c75531325efd55f15ef14e5ca22875d6d53e366 t/const_mbf.t
......@@ -92,8 +94,8 @@ SHA1 1bbe72733abd2f580f94b6a147672f7671260149 t/require.t
SHA1 ad6cc6fe4bb93ae78db4eb7dcb96c95024b963d2 t/round.t
SHA1 8201ea0035861736224992039bcc01d5bd72b778 t/rt-16221.t
SHA1 9d51def046889bf20c6ac2a278f9b3f5f8e36025 t/sub_ali.t
SHA1 7d09d1b2a56c4622536570e6199ce4bab35475ab t/sub_mbf.t
SHA1 211fd2968a2fcbe0384c20c00984f5b8bbbf7688 t/sub_mbi.t
SHA1 d03a42bc484dd3517979c1a3668e38d5c5d26367 t/sub_mbf.t
SHA1 94d13e2f3807f37b1489f7540fa46995f9f78d8e t/sub_mbi.t
SHA1 a9d994551c5ca127c11f5cdd1d8df1d93972c72c t/sub_mif.t
SHA1 22c563a6879c94ce7c8eb72c645f2e374837c34e t/trap.t
SHA1 6170a40ec68d8821a9d5cb7731cbf35c4c0291b6 t/upgrade.inc
......@@ -106,15 +108,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 d374a32db7274aa29c53f530ec4751509147cc10 t/with_sub.t
SHA1 34e18efc281d6538ba91742afa82d50c3b4434ad t/with_sub.t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJV8xYGAAoJEGcmPl2fr166RiEH/jxwvm/84sby96xXXcrUImDf
EicWgwMfh7r986kcV6yr+ejRm+pQizDoKXt5GbNsLt3xtSjRZHIQazIcJYDxsOMk
m9nRp9jIaESM3kk6pA/Al5OIO+peQ25snQpbn+THHUe07UW9az/aDCdYs878yJXN
K9Gwt16LkVVLXgEKWgzXj988fK7+lu7VvlqUzH3GhTKlG2n4OoELjHHFapG4b6kv
CngwNycCNyoJ+JoG5bfKCMNQfqLKEEeNVLG8cpTB6RFJ81qq1QZB52biVZ89yvOH
N4awcVFWXVtMAKNUYdPD4fetBcGigzdpTtYSdF9YB834q/Ai+xKlvlD6BdrcpaA=
=Ky1R
iQEcBAEBAgAGBQJWAEP5AAoJEGcmPl2fr166vegH/0Qm1Z/66sNEhc2jGhRjhlVv
aC2Y76G29bA7TkYhvVNxKZQ0imPBsLINr84jvAPynuwzdKa13EJX46sA1MUW3fmp
ciT4BNoAqv48WUmukh67cm2p/lwNsmA4h4Tz8u7jgDH2r4Ilsh1pUZg6eKTUHLtJ
3Hg3EYAqHuJKtrZQLzECmPpArNDYbHhcQbVI/mhqyIvKTne+qWDbxcvu9YKsAFHp
XwwgOH+PVmqsFiosM6W9FeR8bLnHmTntFFvKKk+Wns4Qo2y0Gxxcq5KwxNgfgoz2
dzWZtdzPqpXEWeqCEDYOMYC/lWu/fCcVamZfyBhTHaTubvari63DsB2hViwSZRc=
=G3gV
-----END PGP SIGNATURE-----
......@@ -12,7 +12,7 @@ package Math::BigFloat;
# _a : accuracy
# _p : precision
$VERSION = '1.999701';
$VERSION = '1.999703';
require 5.006002;
require Exporter;
......@@ -860,19 +860,24 @@ sub blog
{
my ($self,$x,$base,$a,$p,$r) = ref($_[0]) ? (ref($_[0]),@_) : objectify(1,@_);
# 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]))) {
# ($self,$x,$base,$a,$p,$r) = objectify(2,@_);
# }
#}
return $x if $x->modify('blog');
# $base > 0, $base != 1; if $base == undef default to $base == e
# $x >= 0
return $x -> bnan() if $x -> is_nan();
# we need to limit the accuracy to protect against overflow
my $fallback = 0;
my ($scale,@params);
($x,@params) = $x->_find_round_parameters($a,$p,$r);
# also takes care of the "error in _find_round_parameters?" case
return $x->bnan() if $x->{sign} ne '+' || $x->is_zero();
# no rounding at all, so must use fallback
if (scalar @params == 0)
{
......@@ -890,33 +895,67 @@ sub blog
$scale = abs($params[0] || $params[1]) + 4; # take whatever is defined
}
return $x->bzero(@params) if $x->is_one();
# base not defined => base == Euler's number e
if (defined $base)
{
# make object, since we don't feed it through objectify() to still get the
# case of $base == undef
$base = $self->new($base) unless ref($base);
# $base > 0; $base != 1
return $x->bnan() if $base->is_zero() || $base->is_one() ||
$base->{sign} ne '+';
# if $x == $base, we know the result must be 1.0
if ($x->bcmp($base) == 0)
{
$x->bone('+',@params);
if ($fallback)
{
# clear a/p after round, since user did not request it
delete $x->{_a}; delete $x->{_p};
}
return $x;
my $done = 0;
if (defined $base) {
$base = $self -> new($base) unless ref $base;
if ($base -> is_nan() || $base -> is_one()) {
$x -> bnan();
$done = 1;
} elsif ($base -> is_inf() || $base -> is_zero()) {
if ($x -> is_inf() || $x -> is_zero()) {
$x -> bnan();
} else {
$x -> bzero(@params);
}
$done = 1;
} elsif ($base -> is_negative()) { # -inf < base < 0
if ($x -> is_one()) { # x = 1
$x -> bzero(@params);
} elsif ($x == $base) {
$x -> bone('+', @params); # x = base
} else {
$x -> bnan(); # otherwise
}
$done = 1;
} elsif ($x == $base) {
$x -> bone('+', @params); # 0 < base && 0 < x < inf
$done = 1;
}
}
}
# We now know that the base is either undefined or positive and finite.
unless ($done) {
if ($x -> is_inf()) { # x = +/-inf
my $sign = defined $base && $base < 1 ? '-' : '+';
$x -> binf($sign);
$done = 1;
} elsif ($x -> is_neg()) { # -inf < x < 0
$x -> bnan();
$done = 1;
} elsif ($x -> is_one()) { # x = 1
$x -> bzero(@params);
$done = 1;
} elsif ($x -> is_zero()) { # x = 0
my $sign = defined $base && $base < 1 ? '+' : '-';
$x -> binf($sign);
$done = 1;
}
}
if ($done) {
if ($fallback) {
# clear a/p after round, since user did not request it
delete $x->{_a};
delete $x->{_p};
}
return $x;
}
# when user set globals, they would interfere with our calculation, so
# disable them and later re-enable them
no strict 'refs';
my $abr = "$self\::accuracy"; my $ab = $$abr; $$abr = undef;
my $abr = "$self\::accuracy"; my $ab = $$abr; $$abr = undef;
my $pbr = "$self\::precision"; my $pb = $$pbr; $$pbr = undef;
# we also need to disable any set A or P on $x (_find_round_parameters took
# them already into account), since these would interfere, too
......@@ -932,8 +971,8 @@ sub blog
$x = Math::BigFloat->new($x);
$self = ref($x);
}
my $done = 0;
$done = 0;
# If the base is defined and an integer, try to calculate integer result
# first. This is very fast, and in case the real result was found, we can
......
......@@ -18,7 +18,7 @@ package Math::BigInt;
my $class = "Math::BigInt";
use 5.006002;
$VERSION = '1.999701';
$VERSION = '1.999703';
@ISA = qw(Exporter);
@EXPORT_OK = qw(objectify bgcd blcm);
......@@ -94,7 +94,7 @@ use overload
#'oct' => sub { print "oct"; $_[0]; },
# log(N) is log(N, e), where e is Euler's number
'log' => sub { $_[0]->copy()->blog($_[1], undef); },
'log' => sub { $_[0]->copy()->blog(); },
'exp' => sub { $_[0]->copy()->bexp($_[1]); },
'int' => sub { $_[0]->copy(); },
'neg' => sub { $_[0]->copy()->bneg(); },
......@@ -1277,27 +1277,52 @@ sub bdec
sub blog
{
# calculate $x = $a ** $base + $b and return $a (e.g. the log() to base
# $base of $x)
# 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.
# 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 ($self,$x,$base,@r) = (undef,@_);
# objectify is costly, so avoid it
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1])))
{
($self,$x,$base,@r) = objectify(2,@_);
}
if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) {
($self,$x,$base,@r) = objectify(1,@_);
}
return $x if $x->modify('blog');
$base = $self->new($base) if defined $base && !ref $base;
# Handle all exception cases and all trivial cases. I have used Wolfram Alpha
# (http://www.wolframalpha.com) as the reference for these cases.
return $x -> bnan() if $x -> is_nan();
if (defined $base) {
$base = $self -> new($base) unless ref $base;
if ($base -> is_nan() || $base -> is_one()) {
return $x -> bnan();
} elsif ($base -> is_inf() || $base -> is_zero()) {
return $x -> bnan() if $x -> is_inf() || $x -> is_zero();
return $x -> bzero();
} elsif ($base -> is_negative()) { # -inf < base < 0
return $x -> bzero() if $x -> is_one(); # x = 1
return $x -> bone() if $x == $base; # x = base
return $x -> bnan(); # otherwise
}
return $x -> bone() if $x == $base; # 0 < base && 0 < x < inf
}
# inf, -inf, NaN, <0 => NaN
return $x->bnan()
if $x->{sign} ne '+' || (defined $base && $base->{sign} ne '+');
# We now know that the base is either undefined or >= 2 and finite.
return $x -> binf('+') if $x -> is_inf(); # x = +/-inf
return $x -> bnan() if $x -> is_neg(); # -inf < x < 0
return $x -> bzero() if $x -> is_one(); # x = 1
return $x -> binf('-') if $x -> is_zero(); # x = 0
# At this point we are done handling all exception cases and trivial cases.
return $upgrade->blog($upgrade->new($x),$base,@r) if
defined $upgrade;
return $upgrade -> blog($upgrade -> new($x), $base, @r) if defined $upgrade;
# fix for bug #24969:
# the default base is e (Euler's number) which is not an integer
......@@ -1312,7 +1337,7 @@ sub blog
}
my ($rc,$exact) = $CALC->_log_int($x->{value},$base->{value});
return $x->bnan() unless defined $rc; # not possible to take log?
return $x->bnan() unless defined $rc; # not possible to take log?
$x->{value} = $rc;
$x->round(@r);
}
......
......@@ -4,7 +4,7 @@ use 5.006002;
use strict;
# use warnings; # do not use warnings for older Perls
our $VERSION = '1.999701';
our $VERSION = '1.999703';
# Package to store unsigned big integers in decimal and do math with them
......
......@@ -5,7 +5,7 @@ use strict;
# use warnings; # do not use warnings for older Perls
use vars qw/$VERSION/;
$VERSION = '1.999701';
$VERSION = '1.999703';
package Math::BigInt;
......
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2340;
use Test::More tests => 2360;
BEGIN { unshift @INC, 't'; }
......
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3649;
use Test::More tests => 3701;
BEGIN { unshift @INC, 't'; }
......
......@@ -60,6 +60,9 @@ while (<DATA>)
# some unary ops (test the fxxx form, since that is done by AUTOLOAD)
} elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|int|abs)$/) {
$try .= "\$x->f$1();";
# overloaded functions
} elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) {
$try .= "\$x = $f(\$x);";
# some is_xxx test function
} elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) {
$try .= "\$x->$f();";
......@@ -499,16 +502,16 @@ NaN:1:NaN
7:0:1
2:1:2
&flog
0::NaN
0::-inf
-1::NaN
-2::NaN
# base > 0, base != 1
2:-1:NaN
2:0:NaN
2:0:0
2:1:NaN
# log(1) is always 1, regardless of $base
# log(1)
1::0
1:1:0
1:1:NaN
1:2:0
2::0.6931471805599453094172321214581765680755
2.718281828::0.9999999998311266953289851340574956564911
......@@ -1834,3 +1837,23 @@ NaN:NaN
-51.2:-51
12.2:12
-0.4:0
# overloaded functions
&log
-1:NaN
0:-inf
1:0
2:0.6931471805599453094172321214581765680755
3:1.098612288668109691395245236922525704647
123456789:18.63140176616801803319393334796320420971
1234567890987654321:41.657252696908474880343847955484513481
-inf:inf
inf:inf
NaN:NaN
&exp
&sin
&cos
&atan2
&int
&neg
&abs
&sqrt
#!/usr/bin/perl -w
use strict;
use Test::More tests => 2340
use Test::More tests => 2360
+ 5; # own tests
......
......@@ -75,6 +75,9 @@ while (<DATA>)
# some unary ops
} elsif ($f =~ /^b(nan|floor|ceil|int|sstr|neg|abs|sgn|inc|dec|not|sqrt|fac)$/) {
$try .= "\$x->$f();";
# overloaded functions
} elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) {
$try .= "\$x = $f(\$x);";
} elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
$try .= "\$x->$f();";
} elsif ($f eq "exponent"){
......@@ -749,18 +752,40 @@ __DATA__
&^=
5:7:2
&blog
#
NaNlog:2:NaN
122:NaNlog:NaN
NaNlog1:NaNlog:NaN
122:inf:NaN
inf:122:NaN
122:-inf:NaN
-inf:122:NaN
#
122:inf:0
inf:122:inf
122:-inf:0
-inf:122:inf
-inf:-inf:NaN
inf:inf:NaN
0:4:NaN
0:4:-inf
-21:4:NaN
21:-21:NaN
#
0:-inf:NaN
0:-1:NaN
0:0:NaN
0:1:NaN
0:inf:NaN
#
1:-inf:0
1:-1:0
1:0:0
1:1:NaN
1:4:0
1:inf:0
#
inf:-inf:NaN
inf:-1:NaN
inf:0:NaN
inf:1:NaN
inf:4:inf
inf:inf:NaN
#
# normal results
1024:2:10
81:3:4
......@@ -768,6 +793,7 @@ inf:inf:NaN
82:3:4
# 3.9... truncate
80:3:3
4096:2:12
15625:5:6
15626:5:6
15624:5:5
......@@ -785,7 +811,6 @@ inf:inf:NaN
144115188075855872:2:57
288230376151711744:2:58
576460752303423488:2:59
4096:2:12
1329227995784915872903807060280344576:2:120
# $x == $base => result 1
3:3:1
......@@ -2709,3 +2734,23 @@ NaNas_hex:NaN
+inf:inf
-inf:-inf
NaNas_bin:NaN
# overloaded functions
&log
-1:NaN
0:-inf
1:0
2:0
3:1
123456789:18
1234567890987654321:41
-inf:inf
inf:inf
NaN:NaN
&exp
&sin
&cos
&atan2
&int
&neg
&abs
&sqrt
#!/usr/bin/perl -w
use strict;
use Test::More tests => 3649 + 6;
use Test::More tests => 3701 + 6;
use Math::BigInt lib => 'Calc';
......
......@@ -20,14 +20,14 @@ use Math::BigInt;
my $cl = "Math::BigInt";
#############################################################################
# test log($n) in BigInt (broken until 1.80)
# test $n->blog() in BigInt (broken until 1.80)
is ($cl->new(2)->blog(), '0', "blog(2)");
is ($cl->new(288)->blog(), '5',"blog(288)");
is ($cl->new(2000)->blog(), '7', "blog(2000)");
#############################################################################
# test exp($n) in BigInt
# test $n->bexp() in BigInt
is ($cl->new(1)->bexp(), '2', "bexp(1)");
is ($cl->new(2)->bexp(), '7',"bexp(2)");
......@@ -38,7 +38,7 @@ is ($cl->new(3)->bexp(), '20', "bexp(3)");
# BigFloat tests
#############################################################################
# test log(2, N) where N > 67 (broken until 1.82)
# test $n->blog(undef, N) where N > 67 (broken until 1.82)
$cl = "Math::BigFloat";
......
#!perl
BEGIN {
unless ($ENV{AUTHOR_TESTING}) {
require Test::More;
Test::More::plan(skip_all => 'these tests are for release candidate testing');
}
}
use strict;
use warnings;
use Test::More tests => 139;
use Scalar::Util qw< refaddr >;
my $class;
BEGIN { $class = 'Math::BigFloat'; }
BEGIN { use_ok($class) }
while (<DATA>) {
s/\s+\z//;
next if /^#/ || ! /\S/;
# $in0 - the x value
# $in1 - the base
# $out0 - the wanted output value
# $type - the type of the wanted number (real, non-real, ...)
# $expr - mathematical expression of the wanted number
my ($in0, $in1, $out0, $type, $expr) = split /:/;
# Some of the test data use rational numbers.
# - with Math::BigInt, we skip them
# - with Math::BigFloat, we convert them to floats
# - with Math::BigRat, we use them as they are
$in0 = eval $in0 if $in0 =~ m|/|;
$in1 = eval $in1 if $in1 =~ m|/|;
$out0 = eval $out0 if $out0 =~ m|/|;
my ($x, $y); # input values as objects
my ($yo); # copy of input value
my ($got); # test output
my $test = qq|\$x = $class -> new("$in0"); | .
qq|\$y = $class -> new("$in1"); | .
qq|\$yo = \$y -> copy(); | .
qq|\$got = \$x -> blog(\$y);|;
my $desc = "logarithm of $in0 to base $in1";
print("#\n",
"# Now about to execute the following test.\n",
"#\n",
"# $test\n",
"#\n");
if ($in0 ne 'NaN' && $in1 ne 'NaN') {
print("# Enter log($in1, $in0) into Wolfram Alpha",
" (http://www.wolframalpha.com/), and it says that the result",
" is ", length($type) ? $type : "real",
length($expr) ? ": $expr" : "",
".", "\n",
"#\n");
}
eval $test;
die $@ if $@; # this should never happen
subtest $desc, sub {
plan tests => 5,
# Check output.
is(ref($got), $class, "output arg is a $class");
is($got, $out0, 'output arg has the right value');
is(refaddr($got), refaddr($x), 'output arg is the invocand');
# The second argument (if the invocand is the first) shall *not* be
# modified.
is(ref($y), $class, "second input arg is still a $class");
is_deeply($y, $yo, 'second output arg is unmodified');
};
}
__END__
# base = -inf
-inf:-inf:NaN:undefined:
-4:-inf:0::
-2:-inf:0::
-1:-inf:0::
-1/2:-inf:0::
0:-inf:NaN:undefined:
1/2:-inf:0::
1:-inf:0::