summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris 'BinGOs' Williams <chris@bingosnet.co.uk>2016-12-15 14:35:53 +0000
committerChris 'BinGOs' Williams <chris@bingosnet.co.uk>2016-12-15 14:35:53 +0000
commitc9668bc116b106d7b0258fa8661d80692940f09e (patch)
tree907a5a294f43e2cc26e91e175998a7143592b1e6
parentffdff4a12c348019789be9437db6053060c6fd70 (diff)
downloadperl-c9668bc116b106d7b0258fa8661d80692940f09e.tar.gz
Update Math-BigInt to CPAN version 1.999806
[DELTA] 2016-12-13 v1.999806 pjacklam * Add more logic to Makefile.PL regarding INSTALLDIRS (CPAN RT #119199 and #119225). * In the TODO file, remove stuff that has been implemented. 2016-12-11 v1.999805 pjacklam * Fix Makefile.PL so that this module installs over the core version. * Add more tests for _nok() (binomial coefficient "n over k"). These new tests revealed some problems with some of the backend libraries when _nok() was given very large arguments. * Remove t/Math/BigFloat/#Subclass.pm#, which is an Emacs temporary file included by accident. 2016-12-07 v1.999804 pjacklam * Implement as_bytes(), as requested (CPAN RT 119096). Also implement the inverse conversion from_bytes(). This applies to Math::BigInt only. (Alas, these methods will be inherited from Math::BigInt into Math::BigFloat, Math::BigRat etc. where the methods won't work. Fixing this class relationship is an issue of its own.) * Implement _as_bytes() and _from_bytes() in Math::BigInt::Lib. Preferably, the various backend libraries will implement faster versions of their own. Add author test files for testing these methods thorougly. * Fix from_hex(), from_oct(), and from_bin(). - When called as instance methods, the new value should be assigned to the invocand unless the invocand is read-only (a constant). - When called as instance methods, the assigned value was incorrect, if the invocand was inf or NaN. - Add tests to t/from_hex-mbf.t, t/from_oct-mbf.t, and t/from_bin-mbf.t to confirm the fix. - Add new test files t/from_hex-mbi.t, t/from_oct-mbi.t, and t/from_bin-mbi.t for better testing of these methods with Math::BigInt. * Correct typo in Math/BigInt/Lib.pm (otherise -> otherwise) (CPAN RT 118829). * Add POD coverage testing of Math::BigInt::Lib to t/03podcov.t.
-rw-r--r--MANIFEST4
-rwxr-xr-xPorting/Maintainers.pl2
-rw-r--r--cpan/Math-BigInt/lib/Math/BigFloat.pm14
-rw-r--r--cpan/Math-BigInt/lib/Math/BigInt.pm106
-rw-r--r--cpan/Math-BigInt/lib/Math/BigInt/Calc.pm2
-rw-r--r--cpan/Math-BigInt/lib/Math/BigInt/CalcEmu.pm2
-rw-r--r--cpan/Math-BigInt/lib/Math/BigInt/Lib.pm162
-rw-r--r--cpan/Math-BigInt/t/Math/BigFloat/#Subclass.pm#49
-rw-r--r--cpan/Math-BigInt/t/calling.t2
-rw-r--r--cpan/Math-BigInt/t/from_bin-mbf.t44
-rw-r--r--cpan/Math-BigInt/t/from_bin-mbi.t116
-rw-r--r--cpan/Math-BigInt/t/from_hex-mbf.t44
-rw-r--r--cpan/Math-BigInt/t/from_hex-mbi.t116
-rw-r--r--cpan/Math-BigInt/t/from_oct-mbf.t44
-rw-r--r--cpan/Math-BigInt/t/from_oct-mbi.t116
15 files changed, 662 insertions, 161 deletions
diff --git a/MANIFEST b/MANIFEST
index 2c89f48fe6..928cd43dfc 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1725,12 +1725,14 @@ cpan/Math-BigInt/t/dparts-mbi.t Test Math::BigInt
cpan/Math-BigInt/t/eparts-mbf.t Test Math::BigInt
cpan/Math-BigInt/t/eparts-mbi.t Test Math::BigInt
cpan/Math-BigInt/t/from_bin-mbf.t Test Math::BigInt
+cpan/Math-BigInt/t/from_bin-mbi.t
cpan/Math-BigInt/t/from_hex-mbf.t Test Math::BigInt
+cpan/Math-BigInt/t/from_hex-mbi.t
cpan/Math-BigInt/t/from_oct-mbf.t Test Math::BigInt
+cpan/Math-BigInt/t/from_oct-mbi.t
cpan/Math-BigInt/t/inf_nan.t Special tests for inf and *NaN* handling
cpan/Math-BigInt/t/isa.t Test for Math::BigInt inheritance
cpan/Math-BigInt/t/lib_load.t Test sane lib names
-cpan/Math-BigInt/t/Math/BigFloat/#Subclass.pm#
cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm Empty subclass of BigFloat for test
cpan/Math-BigInt/t/Math/BigInt/BareCalc.pm Bigint's simulation of Calc
cpan/Math-BigInt/t/Math/BigInt/Lib/Minimal.pm
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index e5a2064685..c672267472 100755
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -761,7 +761,7 @@ use File::Glob qw(:case);
},
'Math::BigInt' => {
- 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-1.999803.tar.gz',
+ 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-1.999806.tar.gz',
'FILES' => q[cpan/Math-BigInt],
'EXCLUDED' => [
qr{^examples/},
diff --git a/cpan/Math-BigInt/lib/Math/BigFloat.pm b/cpan/Math-BigInt/lib/Math/BigFloat.pm
index eee9897703..bcbb2bfd2b 100644
--- a/cpan/Math-BigInt/lib/Math/BigFloat.pm
+++ b/cpan/Math-BigInt/lib/Math/BigFloat.pm
@@ -19,7 +19,7 @@ use warnings;
use Carp ();
use Math::BigInt ();
-our $VERSION = '1.999803';
+our $VERSION = '1.999806';
require Exporter;
our @ISA = qw/Math::BigInt/;
@@ -517,6 +517,10 @@ sub from_hex {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_hex');
+
my $str = shift;
# If called as a class method, initialize a new object.
@@ -602,6 +606,10 @@ sub from_oct {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_oct');
+
my $str = shift;
# If called as a class method, initialize a new object.
@@ -684,6 +692,10 @@ sub from_bin {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_bin');
+
my $str = shift;
# If called as a class method, initialize a new object.
diff --git a/cpan/Math-BigInt/lib/Math/BigInt.pm b/cpan/Math-BigInt/lib/Math/BigInt.pm
index bd98fda1a0..ed6e79fa1c 100644
--- a/cpan/Math-BigInt/lib/Math/BigInt.pm
+++ b/cpan/Math-BigInt/lib/Math/BigInt.pm
@@ -20,7 +20,7 @@ use warnings;
use Carp ();
-our $VERSION = '1.999803';
+our $VERSION = '1.999806';
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(objectify bgcd blcm);
@@ -719,6 +719,10 @@ sub from_hex {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_hex');
+
my $str = shift;
# If called as a class method, initialize a new object.
@@ -750,9 +754,8 @@ sub from_hex {
# Place the sign.
- if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
- $self->{sign} = '-';
- }
+ $self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
+ ? '-' : '+';
return $self;
}
@@ -770,6 +773,10 @@ sub from_oct {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_oct');
+
my $str = shift;
# If called as a class method, initialize a new object.
@@ -800,9 +807,8 @@ sub from_oct {
# Place the sign.
- if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
- $self->{sign} = '-';
- }
+ $self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
+ ? '-' : '+';
return $self;
}
@@ -820,6 +826,10 @@ sub from_bin {
my $selfref = ref $self;
my $class = $selfref || $self;
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_bin');
+
my $str = shift;
# If called as a class method, initialize a new object.
@@ -851,9 +861,8 @@ sub from_bin {
# Place the sign.
- if ($sign eq '-' && ! $CALC->_is_zero($self->{value})) {
- $self->{sign} = '-';
- }
+ $self->{sign} = $sign eq '-' && ! $CALC->_is_zero($self->{value})
+ ? '-' : '+';
return $self;
}
@@ -864,6 +873,27 @@ sub from_bin {
return $self->bnan();
}
+# Create a Math::BigInt from a byte string.
+
+sub from_bytes {
+ my $self = shift;
+ my $selfref = ref $self;
+ my $class = $selfref || $self;
+
+ # Don't modify constant (read-only) objects.
+
+ return if $selfref && $self->modify('from_bytes');
+
+ my $str = shift;
+
+ # If called as a class method, initialize a new object.
+
+ $self = $class -> bzero() unless $selfref;
+ $self -> {sign} = '+';
+ $self -> {value} = $CALC -> _from_bytes($str);
+ return $self;
+}
+
sub bzero {
# create/assign '+0'
@@ -878,6 +908,9 @@ sub bzero {
my $class = $selfref || $self;
$self->import() if $IMPORT == 0; # make require work
+
+ # Don't modify constant (read-only) objects.
+
return if $selfref && $self->modify('bzero');
$self = bless {}, $class unless $selfref;
@@ -915,6 +948,9 @@ sub bone {
my $class = $selfref || $self;
$self->import() if $IMPORT == 0; # make require work
+
+ # Don't modify constant (read-only) objects.
+
return if $selfref && $self->modify('bone');
my $sign = shift;
@@ -964,6 +1000,9 @@ sub binf {
}
$self->import() if $IMPORT == 0; # make require work
+
+ # Don't modify constant (read-only) objects.
+
return if $selfref && $self->modify('binf');
my $sign = shift;
@@ -998,6 +1037,9 @@ sub bnan {
}
$self->import() if $IMPORT == 0; # make require work
+
+ # Don't modify constant (read-only) objects.
+
return if $selfref && $self->modify('bnan');
$self = bless {}, $class unless $selfref;
@@ -3478,6 +3520,16 @@ sub as_bin {
return $s . $CALC->_as_bin($x->{value});
}
+sub as_bytes {
+ # return a byte string
+ my $x = shift;
+ $x = $class->new($x) if !ref($x);
+
+ Carp::croak("as_bytes() requires a finite, non-negative integer")
+ if $x -> is_neg() || ! $x -> is_int();
+ return $CALC->_as_bytes($x->{value});
+}
+
###############################################################################
# Other conversion methods
###############################################################################
@@ -4219,6 +4271,7 @@ Math::BigInt - Arbitrary size integer/float math package
$x->as_hex(); # as signed hexadecimal string with prefixed 0x
$x->as_bin(); # as signed binary string with prefixed 0b
$x->as_oct(); # as signed octal string with prefixed 0
+ $x->as_bytes(); # as byte string
# Other conversion methods
@@ -4512,6 +4565,31 @@ Interpret the input as a binary string. A "0b" or "b" prefix is optional. A
single underscore character may be placed right after the prefix, if present,
or between any two digits. If the input is invalid, a NaN is returned.
+=item from_bytes()
+
+ $x = Math::BigInt->from_bytes("\xf3\x6b"); # $x = 62315
+
+Interpret the input as a byte string, assuming big endian byte order. The
+output is always a non-negative, finite integer.
+
+In some special cases, from_bytes() matches the conversion done by unpack():
+
+ $b = "\x4e"; # one char byte string
+ $x = Math::BigInt->from_bytes($b); # = 78
+ $y = unpack "C", $b; # ditto, but scalar
+
+ $b = "\xf3\x6b"; # two char byte string
+ $x = Math::BigInt->from_bytes($b); # = 62315
+ $y = unpack "S>", $b; # ditto, but scalar
+
+ $b = "\x2d\xe0\x49\xad"; # four char byte string
+ $x = Math::BigInt->from_bytes($b); # = 769673645
+ $y = unpack "L>", $b; # ditto, but scalar
+
+ $b = "\x2d\xe0\x49\xad\x2d\xe0\x49\xad"; # eight char byte string
+ $x = Math::BigInt->from_bytes($b); # = 3305723134637787565
+ $y = unpack "Q>", $b; # ditto, but scalar
+
=item bzero()
$x = Math::BigInt->bzero();
@@ -5321,6 +5399,14 @@ prefixed by "0b".
Returns a string representing the number using octal notation. The output is
prefixed by "0".
+=item as_bytes()
+
+ $x = Math::BigInt->new("1667327589");
+ $s = $x->as_bytes(); # $s = "cafe"
+
+Returns a byte string representing the number using big endian byte order. The
+invocand must be a non-negative, finite integer.
+
=back
=head2 Other conversion methods
diff --git a/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm b/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm
index c0a089b585..5717e764e1 100644
--- a/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm
+++ b/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm
@@ -7,7 +7,7 @@ use warnings;
use Carp;
use Math::BigInt::Lib;
-our $VERSION = '1.999803';
+our $VERSION = '1.999806';
our @ISA = ('Math::BigInt::Lib');
diff --git a/cpan/Math-BigInt/lib/Math/BigInt/CalcEmu.pm b/cpan/Math-BigInt/lib/Math/BigInt/CalcEmu.pm
index 13cc8e8ff8..572f9de52f 100644
--- a/cpan/Math-BigInt/lib/Math/BigInt/CalcEmu.pm
+++ b/cpan/Math-BigInt/lib/Math/BigInt/CalcEmu.pm
@@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;
-our $VERSION = '1.999803';
+our $VERSION = '1.999806';
package Math::BigInt;
diff --git a/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm b/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm
index 32ccef9931..dea1b0c0a3 100644
--- a/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm
+++ b/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm
@@ -4,7 +4,7 @@ use 5.006001;
use strict;
use warnings;
-our $VERSION = '1.999803';
+our $VERSION = '1.999806';
use Carp;
@@ -589,8 +589,8 @@ sub _fac {
sub _log_int {
# calculate integer log of $x to base $base
- # calculate integer log of $x to base $base
# ref to array, ref to array - return ref to array
+
my ($class, $x, $base) = @_;
# X == 0 => NaN
@@ -981,8 +981,24 @@ sub _as_oct {
return '0' . $str; # yes, 0 becomes "00".
}
+sub _as_bytes {
+ # convert a decimal number to a byte string
+ my ($class, $x) = @_;
+ my $str = '';
+ my $tmp = $class -> _copy($x);
+ my $base = $class -> _new("256");
+ my $rem;
+ until ($class -> _is_zero($tmp)) {
+ ($tmp, $rem) = $class -> _div($tmp, $base);
+ my $byte = pack 'C', $rem;
+ $str = $byte . $str;
+ }
+ return "\x00" unless length($str);
+ return $str;
+}
+
sub _from_oct {
- # convert a octal number to decimal
+ # convert a octal string to a decimal number
my ($class, $str) = @_;
$str =~ s/^0+//;
my $x = $class -> _zero();
@@ -996,7 +1012,7 @@ sub _from_oct {
}
sub _from_hex {
- # convert a hex number to decimal
+ # convert a hexadecimal string to a decimal number
my ($class, $str) = @_;
$str =~ s/^0[Xx]//;
my $x = $class -> _zero();
@@ -1010,7 +1026,7 @@ sub _from_hex {
}
sub _from_bin {
- # convert a hex number to decimal
+ # convert a binary string to a decimal number
my ($class, $str) = @_;
$str =~ s/^0[Bb]//;
my $x = $class -> _zero();
@@ -1023,6 +1039,20 @@ sub _from_bin {
return $x;
}
+sub _from_bytes {
+ # convert a byte string to a decimal number
+ my ($class, $str) = @_;
+ my $x = $class -> _zero();
+ my $base = $class -> _new("256");
+ my $n = length($str);
+ for (my $i = 0 ; $i < $n ; ++$i) {
+ $x = $class -> _mul($x, $base);
+ my $byteval = $class -> _new(unpack 'C', substr($str, $i, 1));
+ $x = $class -> _add($x, $byteval);
+ }
+ return $x;
+}
+
##############################################################################
# special modulus functions
@@ -1223,7 +1253,7 @@ comparison routines.
=over 4
-=item I<api_version()>
+=item api_version()
Return API version as a Perl scalar, 1 for Math::BigInt v1.70, 2 for
Math::BigInt v1.83.
@@ -1240,99 +1270,105 @@ However, computations will be very slow without _mul() and _div().
=over 4
-=item I<_new(STR)>
+=item _new(STR)
Convert a string representing an unsigned decimal number to an object
representing the same number. The input is normalize, i.e., it matches
C<^(0|[1-9]\d*)$>.
-=item I<_zero()>
+=item _zero()
Return an object representing the number zero.
-=item I<_one()>
+=item _one()
Return an object representing the number one.
-=item I<_two()>
+=item _two()
Return an object representing the number two.
-=item I<_ten()>
+=item _ten()
Return an object representing the number ten.
-=item I<_from_bin(STR)>
+=item _from_bin(STR)
Return an object given a string representing a binary number. The input has a
'0b' prefix and matches the regular expression C<^0[bB](0|1[01]*)$>.
-=item I<_from_oct(STR)>
+=item _from_oct(STR)
Return an object given a string representing an octal number. The input has a
'0' prefix and matches the regular expression C<^0[1-7]*$>.
-=item I<_from_hex(STR)>
+=item _from_hex(STR)
Return an object given a string representing a hexadecimal number. The input
has a '0x' prefix and matches the regular expression
C<^0x(0|[1-9a-fA-F][\da-fA-F]*)$>.
+=item _from_bytes(STR)
+
+Returns an object given a byte string representing the number. The byte string
+is in big endian byte order, so the two-byte input string "\x01\x00" should
+give an output value representing the number 256.
+
=back
=head3 Mathematical functions
=over 4
-=item I<_add(OBJ1, OBJ2)>
+=item _add(OBJ1, OBJ2)
Returns the result of adding OBJ2 to OBJ1.
-=item I<_mul(OBJ1, OBJ2)>
+=item _mul(OBJ1, OBJ2)
Returns the result of multiplying OBJ2 and OBJ1.
-=item I<_div(OBJ1, OBJ2)>
+=item _div(OBJ1, OBJ2)
Returns the result of dividing OBJ1 by OBJ2 and truncating the result to an
integer.
-=item I<_sub(OBJ1, OBJ2, FLAG)>
+=item _sub(OBJ1, OBJ2, FLAG)
-=item I<_sub(OBJ1, OBJ2)>
+=item _sub(OBJ1, OBJ2)
Returns the result of subtracting OBJ2 by OBJ1. If C<flag> is false or omitted,
OBJ1 might be modified. If C<flag> is true, OBJ2 might be modified.
-=item I<_dec(OBJ)>
+=item _dec(OBJ)
Decrement OBJ by one.
-=item I<_inc(OBJ)>
+=item _inc(OBJ)
Increment OBJ by one.
-=item I<_mod(OBJ1, OBJ2)>
+=item _mod(OBJ1, OBJ2)
Return OBJ1 modulo OBJ2, i.e., the remainder after dividing OBJ1 by OBJ2.
-=item I<_sqrt(OBJ)>
+=item _sqrt(OBJ)
Return the square root of the object, truncated to integer.
-=item I<_root(OBJ, N)>
+=item _root(OBJ, N)
Return Nth root of the object, truncated to int. N is E<gt>= 3.
-=item I<_fac(OBJ)>
+=item _fac(OBJ)
Return factorial of object (1*2*3*4*...).
-=item I<_pow(OBJ1, OBJ2)>
+=item _pow(OBJ1, OBJ2)
Return OBJ1 to the power of OBJ2. By convention, 0**0 = 1.
-=item I<_modinv(OBJ1, OBJ2)>
+=item _modinv(OBJ1, OBJ2)
Return modular multiplicative inverse, i.e., return OBJ3 so that
@@ -1349,11 +1385,11 @@ must either return an object representing the number 3 and a "+" sign, since
(3*7) % 5 = 1 % 5, or an object representing the number 2 and "-" sign,
since (-2*7) % 5 = 1 % 5.
-=item I<_modpow(OBJ1, OBJ2, OBJ3)>
+=item _modpow(OBJ1, OBJ2, OBJ3)
Return modular exponentiation, (OBJ1 ** OBJ2) % OBJ3.
-=item I<_rsft(OBJ, N, B)>
+=item _rsft(OBJ, N, B)
Shift object N digits right in base B and return the resulting object. This is
equivalent to performing integer division by B**N and discarding the remainder,
@@ -1364,24 +1400,24 @@ For instance, if the object $obj represents the hexadecimal number 0xabcde,
then C<_rsft($obj, 2, 16)> returns an object representing the number 0xabc. The
"remainer", 0xde, is discarded and not returned.
-=item I<_lsft(OBJ, N, B)>
+=item _lsft(OBJ, N, B)
Shift the object N digits left in base B. This is equivalent to multiplying by
B**N, except that it might be much faster, depending on how the number is
represented internally.
-=item I<_log_int(OBJ, B)>
+=item _log_int(OBJ, B)
Return integer log of OBJ to base BASE. This method has two output arguments,
the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ is the exact
result, 0 if the result was truncted to give OBJ, and undef if it is unknown
whether OBJ is the exact result.
-=item I<_gcd(OBJ1, OBJ2)>
+=item _gcd(OBJ1, OBJ2)
Return the greatest common divisor of OBJ1 and OBJ2.
-=item I<_lcm(OBJ1, OBJ2)>
+=item _lcm(OBJ1, OBJ2)
Return the least common multiple of OBJ1 and OBJ2.
@@ -1393,17 +1429,17 @@ Each of these methods may modify the first input argument.
=over 4
-=item I<_and(OBJ1, OBJ2)>
+=item _and(OBJ1, OBJ2)
Return bitwise and. If necessary, the smallest number is padded with leading
zeros.
-=item I<_or(OBJ1, OBJ2)>
+=item _or(OBJ1, OBJ2)
Return bitwise or. If necessary, the smallest number is padded with leading
zeros.
-=item I<_xor(OBJ1, OBJ2)>
+=item _xor(OBJ1, OBJ2)
Return bitwise exclusive or. If necessary, the smallest number is padded
with leading zeros.
@@ -1414,31 +1450,31 @@ with leading zeros.
=over 4
-=item I<_is_zero(OBJ)>
+=item _is_zero(OBJ)
Returns a true value if OBJ is zero, and false value otherwise.
-=item I<_is_one(OBJ)>
+=item _is_one(OBJ)
Returns a true value if OBJ is one, and false value otherwise.
-=item I<_is_two(OBJ)>
+=item _is_two(OBJ)
Returns a true value if OBJ is two, and false value otherwise.
-=item I<_is_ten(OBJ)>
+=item _is_ten(OBJ)
Returns a true value if OBJ is ten, and false value otherwise.
-=item I<_is_even(OBJ)>
+=item _is_even(OBJ)
Return a true value if OBJ is an even integer, and a false value otherwise.
-=item I<_is_odd(OBJ)>
+=item _is_odd(OBJ)
Return a true value if OBJ is an even integer, and a false value otherwise.
-=item I<_acmp(OBJ1, OBJ2)>
+=item _acmp(OBJ1, OBJ2)
Compare OBJ1 and OBJ2 and return -1, 0, or 1, if OBJ1 is less than, equal
to, or larger than OBJ2, respectively.
@@ -1449,17 +1485,17 @@ to, or larger than OBJ2, respectively.
=over 4
-=item I<_str(OBJ)>
+=item _str(OBJ)
Return a string representing the object. The returned string should have no
leading zeros, i.e., it should match C<^(0|[1-9]\d*)$>.
-=item I<_as_bin(OBJ)>
+=item _as_bin(OBJ)
Return the binary string representation of the number. The string must have a
'0b' prefix.
-=item I<_as_oct(OBJ)>
+=item _as_oct(OBJ)
Return the octal string representation of the number. The string must have
a '0x' prefix.
@@ -1468,18 +1504,24 @@ Note: This method was required from Math::BigInt version 1.78, but the required
API version number was not incremented, so there are older libraries that
support API version 1, but do not support C<_as_oct()>.
-=item I<_as_hex(OBJ)>
+=item _as_hex(OBJ)
Return the hexadecimal string representation of the number. The string must
have a '0x' prefix.
+=item _as_bytes(OBJ)
+
+Return a byte string representation of the number. The byte string is in big
+endian byte order, so if the object represents the number 256, the output
+should be the two-byte string "\x01\x00".
+
=back
=head3 Numeric conversion
=over 4
-=item I<_num(OBJ)>
+=item _num(OBJ)
Given an object, return a Perl scalar number (int/float) representing this
number.
@@ -1490,29 +1532,29 @@ number.
=over 4
-=item I<_copy(OBJ)>
+=item _copy(OBJ)
Return a true copy of the object.
-=item I<_len(OBJ)>
+=item _len(OBJ)
Returns the number of the decimal digits in the number. The output is a
Perl scalar.
-=item I<_zeros(OBJ)>
+=item _zeros(OBJ)
Return the number of trailing decimal zeros. The output is a Perl scalar.
-=item I<_digit(OBJ, N)>
+=item _digit(OBJ, N)
Return the Nth digit as a Perl scalar. N is a Perl scalar, where zero refers to
the rightmost (least significant) digit, and negative values count from the
left (most significant digit). If $obj represents the number 123, then
I<$obj->_digit(0)> is 3 and I<_digit(123, -1)> is 1.
-=item I<_check(OBJ)>
+=item _check(OBJ)
-Return true if the object is invalid and false otherise. Preferably, the true
+Return true if the object is invalid and false otherwise. Preferably, the true
value is a string describing the problem with the object. This is a check
routine to test the internal state of the object for corruption.
@@ -1526,7 +1568,7 @@ The following methods are required for an API version of 2 or greater.
=over 4
-=item I<_1ex(N)>
+=item _1ex(N)
Return an object representing the number 10**N where N E<gt>= 0 is a Perl
scalar.
@@ -1537,7 +1579,7 @@ scalar.
=over 4
-=item I<_nok(OBJ1, OBJ2)>
+=item _nok(OBJ1, OBJ2)
Return the binomial coefficient OBJ1 over OBJ1.
@@ -1547,7 +1589,7 @@ Return the binomial coefficient OBJ1 over OBJ1.
=over 4
-=item I<_alen(OBJ)>
+=item _alen(OBJ)
Return the approximate number of decimal digits of the object. The output is a
Perl scalar.
@@ -1564,15 +1606,15 @@ slow) fallback routines to emulate these:
=over 4
-=item I<_signed_or(OBJ1, OBJ2, SIGN1, SIGN2)>
+=item _signed_or(OBJ1, OBJ2, SIGN1, SIGN2)
Return the signed bitwise or.
-=item I<_signed_and(OBJ1, OBJ2, SIGN1, SIGN2)>
+=item _signed_and(OBJ1, OBJ2, SIGN1, SIGN2)
Return the signed bitwise and.
-=item I<_signed_xor(OBJ1, OBJ2, SIGN1, SIGN2)>
+=item _signed_xor(OBJ1, OBJ2, SIGN1, SIGN2)
Return the signed bitwise exclusive or.
diff --git a/cpan/Math-BigInt/t/Math/BigFloat/#Subclass.pm# b/cpan/Math-BigInt/t/Math/BigFloat/#Subclass.pm#
deleted file mode 100644
index f35e26710c..0000000000
--- a/cpan/Math-BigInt/t/Math/BigFloat/#Subclass.pm#
+++ /dev/null
@@ -1,49 +0,0 @@
-#!perl
-
-# for testing subclassing Math::BigFloat
-
-package Math::BigFloat::Subclass;
-
-require 5.006;
-
-use strict;
-use warnings;
-
-use Exporter;
-use Math::BigFloat 1.38;
-
-our ($accuracy, $precision, $round_mode, $div_scale);
-
-our @ISA = qw(Exporter Math::BigFloat);
-
-our $VERSION = "0.06";
-
-use overload; # inherit overload from BigInt
-
-# Globals
-$accuracy = $precision = undef;
-$round_mode = 'even';
-$div_scale = 40;
-
-sub new {
- my $proto = shift;
- my $class = ref($proto) || $proto;
-
- my $value = shift;
- my $a = $accuracy; $a = $_[0] if defined $_[0];
- my $p = $precision; $p = $_[1] if defined $_[1];
- # Store the floating point value
- my $self = Math::BigFloat->new($value, $a, $p, $round_mode);
- bless $self, $class;
- $self->{'_custom'} = 1; # make sure this never goes away
- return $self;
-}
-
-BEGIN {
- *objectify = \&Math::BigInt::objectify;
- # to allow Math::BigFloat::Subclass::bgcd( ... ) style calls
- *bgcd = \&Math::BigFloat::bgcd;
- *blcm = \&Math::BigFloat::blcm;
-}
-
-1;
diff --git a/cpan/Math-BigInt/t/calling.t b/cpan/Math-BigInt/t/calling.t
index 56f0b46d8b..ad3104442e 100644
--- a/cpan/Math-BigInt/t/calling.t
+++ b/cpan/Math-BigInt/t/calling.t
@@ -6,7 +6,7 @@ use strict;
use warnings;
use lib 't';
-my $VERSION = '1.999803'; # adjust manually to match latest release
+my $VERSION = '1.999806'; # adjust manually to match latest release
use Test::More tests => 5;
diff --git a/cpan/Math-BigInt/t/from_bin-mbf.t b/cpan/Math-BigInt/t/from_bin-mbf.t
index a8c7527e8a..e24cd3b665 100644
--- a/cpan/Math-BigInt/t/from_bin-mbf.t
+++ b/cpan/Math-BigInt/t/from_bin-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 183;
my $class;
@@ -16,23 +16,43 @@ while (<DATA>) {
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
- my $x;
- my $test = qq|\$x = $class -> from_bin("$in0");|;
- my $desc = $test;
+ # As class method.
- eval $test;
- die $@ if $@; # this should never happen
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_bin("$in0");|;
- subtest $desc, sub {
- plan tests => 2,
+ eval $test;
+ die $@ if $@; # this should never happen
- # Check output.
+ subtest $test, sub {
+ plan tests => 2,
- is(ref($x), $class, "output arg is a $class");
- is($x, $out0, 'output arg has the right value');
- };
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_bin("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
}
__END__
diff --git a/cpan/Math-BigInt/t/from_bin-mbi.t b/cpan/Math-BigInt/t/from_bin-mbi.t
new file mode 100644
index 0000000000..b33eb6794b
--- /dev/null
+++ b/cpan/Math-BigInt/t/from_bin-mbi.t
@@ -0,0 +1,116 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 344;
+
+my $class;
+
+BEGIN { $class = 'Math::BigInt'; }
+BEGIN { use_ok($class); }
+
+while (<DATA>) {
+ s/#.*$//; # remove comments
+ s/\s+$//; # remove trailing whitespace
+ next unless length; # skip empty lines
+
+ my ($in0, $out0) = split /:/;
+
+ # As class method.
+
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_bin("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_bin("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
+}
+
+__END__
+
+0b0:0
+0b1:1
+0b10:2
+0b11:3
+0b100:4
+0b101:5
+0b110:6
+0b111:7
+0b1000:8
+0b1001:9
+0b1010:10
+0b1011:11
+0b1100:12
+0b1101:13
+0b1110:14
+0b1111:15
+0b10000:16
+0b10001:17
+
+0b11111110:254
+0b11111111:255
+0b100000000:256
+0b100000001:257
+
+0b1111111111111110:65534
+0b1111111111111111:65535
+0b10000000000000000:65536
+0b10000000000000001:65537
+
+0b111111111111111111111110:16777214
+0b111111111111111111111111:16777215
+0b1000000000000000000000000:16777216
+0b1000000000000000000000001:16777217
+
+0b11111111111111111111111111111110:4294967294
+0b11111111111111111111111111111111:4294967295
+0b100000000000000000000000000000000:4294967296
+0b100000000000000000000000000000001:4294967297
+
+0b1111111111111111111111111111111111111110:1099511627774
+0b1111111111111111111111111111111111111111:1099511627775
+0b10000000000000000000000000000000000000000:1099511627776
+0b10000000000000000000000000000000000000001:1099511627777
+
+0b111111111111111111111111111111111111111111111110:281474976710654
+0b111111111111111111111111111111111111111111111111:281474976710655
+0b1000000000000000000000000000000000000000000000000:281474976710656
+0b1000000000000000000000000000000000000000000000001:281474976710657
+
+0b11111111111111111111111111111111111111111111111111111110:72057594037927934
+0b11111111111111111111111111111111111111111111111111111111:72057594037927935
+0b100000000000000000000000000000000000000000000000000000000:72057594037927936
+0b100000000000000000000000000000000000000000000000000000001:72057594037927937
+
+NaN:NaN
++inf:NaN
+-inf:NaN
diff --git a/cpan/Math-BigInt/t/from_hex-mbf.t b/cpan/Math-BigInt/t/from_hex-mbf.t
index b45917acff..1a3994923a 100644
--- a/cpan/Math-BigInt/t/from_hex-mbf.t
+++ b/cpan/Math-BigInt/t/from_hex-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 183;
my $class;
@@ -16,23 +16,43 @@ while (<DATA>) {
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
- my $x;
- my $test = qq|\$x = $class -> from_hex("$in0");|;
- my $desc = $test;
+ # As class method.
- eval $test;
- die $@ if $@; # this should never happen
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_hex("$in0");|;
- subtest $desc, sub {
- plan tests => 2,
+ eval $test;
+ die $@ if $@; # this should never happen
- # Check output.
+ subtest $test, sub {
+ plan tests => 2,
- is(ref($x), $class, "output arg is a $class");
- is($x, $out0, 'output arg has the right value');
- };
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_hex("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
}
__END__
diff --git a/cpan/Math-BigInt/t/from_hex-mbi.t b/cpan/Math-BigInt/t/from_hex-mbi.t
new file mode 100644
index 0000000000..2bb130110b
--- /dev/null
+++ b/cpan/Math-BigInt/t/from_hex-mbi.t
@@ -0,0 +1,116 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 344;
+
+my $class;
+
+BEGIN { $class = 'Math::BigInt'; }
+BEGIN { use_ok($class); }
+
+while (<DATA>) {
+ s/#.*$//; # remove comments
+ s/\s+$//; # remove trailing whitespace
+ next unless length; # skip empty lines
+
+ my ($in0, $out0) = split /:/;
+
+ # As class method.
+
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_hex("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_hex("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
+}
+
+__END__
+
+0x0:0
+0x1:1
+0x2:2
+0x3:3
+0x4:4
+0x5:5
+0x6:6
+0x7:7
+0x8:8
+0x9:9
+0xa:10
+0xb:11
+0xc:12
+0xd:13
+0xe:14
+0xf:15
+0x10:16
+0x11:17
+
+0xfe:254
+0xff:255
+0x100:256
+0x101:257
+
+0xfffe:65534
+0xffff:65535
+0x10000:65536
+0x10001:65537
+
+0xfffffe:16777214
+0xffffff:16777215
+0x1000000:16777216
+0x1000001:16777217
+
+0xfffffffe:4294967294
+0xffffffff:4294967295
+0x100000000:4294967296
+0x100000001:4294967297
+
+0xfffffffffe:1099511627774
+0xffffffffff:1099511627775
+0x10000000000:1099511627776
+0x10000000001:1099511627777
+
+0xfffffffffffe:281474976710654
+0xffffffffffff:281474976710655
+0x1000000000000:281474976710656
+0x1000000000001:281474976710657
+
+0xfffffffffffffe:72057594037927934
+0xffffffffffffff:72057594037927935
+0x100000000000000:72057594037927936
+0x100000000000001:72057594037927937
+
+NaN:NaN
++inf:NaN
+-inf:NaN
diff --git a/cpan/Math-BigInt/t/from_oct-mbf.t b/cpan/Math-BigInt/t/from_oct-mbf.t
index 7e584549af..b735bd5c6f 100644
--- a/cpan/Math-BigInt/t/from_oct-mbf.t
+++ b/cpan/Math-BigInt/t/from_oct-mbf.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 27;
+use Test::More tests => 183;
my $class;
@@ -16,23 +16,43 @@ while (<DATA>) {
next unless length; # skip empty lines
my ($in0, $out0) = split /:/;
- my $x;
- my $test = qq|\$x = $class -> from_oct("$in0");|;
- my $desc = $test;
+ # As class method.
- eval $test;
- die $@ if $@; # this should never happen
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_oct("$in0");|;
- subtest $desc, sub {
- plan tests => 2,
+ eval $test;
+ die $@ if $@; # this should never happen
- # Check output.
+ subtest $test, sub {
+ plan tests => 2,
- is(ref($x), $class, "output arg is a $class");
- is($x, $out0, 'output arg has the right value');
- };
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_oct("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
}
__END__
diff --git a/cpan/Math-BigInt/t/from_oct-mbi.t b/cpan/Math-BigInt/t/from_oct-mbi.t
new file mode 100644
index 0000000000..3a7833dc46
--- /dev/null
+++ b/cpan/Math-BigInt/t/from_oct-mbi.t
@@ -0,0 +1,116 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 344;
+
+my $class;
+
+BEGIN { $class = 'Math::BigInt'; }
+BEGIN { use_ok($class); }
+
+while (<DATA>) {
+ s/#.*$//; # remove comments
+ s/\s+$//; # remove trailing whitespace
+ next unless length; # skip empty lines
+
+ my ($in0, $out0) = split /:/;
+
+ # As class method.
+
+ {
+ my $x;
+ my $test = qq|\$x = $class -> from_oct("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+
+ # As instance method.
+
+ {
+ for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
+ my $x;
+ my $test = qq|\$x = $class -> new("$str");|
+ . qq| \$x -> from_oct("$in0");|;
+
+ eval $test;
+ die $@ if $@; # this should never happen
+
+ subtest $test, sub {
+ plan tests => 2,
+
+ is(ref($x), $class, "output arg is a $class");
+ is($x, $out0, 'output arg has the right value');
+ };
+ }
+ }
+}
+
+__END__
+
+0:0
+1:1
+2:2
+3:3
+4:4
+5:5
+6:6
+7:7
+10:8
+11:9
+12:10
+13:11
+14:12
+15:13
+16:14
+17:15
+20:16
+21:17
+
+376:254
+377:255
+400:256
+401:257
+
+177776:65534
+177777:65535
+200000:65536
+200001:65537
+
+77777776:16777214
+77777777:16777215
+100000000:16777216
+100000001:16777217
+
+37777777776:4294967294
+37777777777:4294967295
+40000000000:4294967296
+40000000001:4294967297
+
+17777777777776:1099511627774
+17777777777777:1099511627775
+20000000000000:1099511627776
+20000000000001:1099511627777
+
+7777777777777776:281474976710654
+7777777777777777:281474976710655
+10000000000000000:281474976710656
+10000000000000001:281474976710657
+
+3777777777777777776:72057594037927934
+3777777777777777777:72057594037927935
+4000000000000000000:72057594037927936
+4000000000000000001:72057594037927937
+
+NaN:NaN
++inf:NaN
+-inf:NaN