summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Math
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-04-26 22:16:26 +0000
committerKarl Berry <karl@freefriends.org>2015-04-26 22:16:26 +0000
commit342e672574c4e67d510e46ab6acd0e21a7d0cf54 (patch)
tree79e04202d08c0404bbd780bd26c1e34710e539b6 /Master/tlpkg/tlperl/lib/Math
parentbe2706af7c57a0ef0f4d4e9f684ca4ef74922a82 (diff)
(tl)perl 5.20.2 for windows, from siep
git-svn-id: svn://tug.org/texlive/trunk@37064 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Math')
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigFloat.pm161
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigFloat/Trace.pm2
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigInt.pm646
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigInt/Calc.pm8
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigInt/CalcEmu.pm14
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigInt/FastCalc.pm2
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigInt/Trace.pm2
-rw-r--r--Master/tlpkg/tlperl/lib/Math/BigRat.pm10
-rwxr-xr-xMaster/tlpkg/tlperl/lib/Math/Int64.pm53
-rwxr-xr-xMaster/tlpkg/tlperl/lib/Math/Int64/die_on_overflow.pm16
-rwxr-xr-xMaster/tlpkg/tlperl/lib/Math/Int64/native_if_available.pm30
-rwxr-xr-xMaster/tlpkg/tlperl/lib/Math/UInt64.pm19
12 files changed, 527 insertions, 436 deletions
diff --git a/Master/tlpkg/tlperl/lib/Math/BigFloat.pm b/Master/tlpkg/tlperl/lib/Math/BigFloat.pm
index b0f2e4df508..fb1d20690bc 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigFloat.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigFloat.pm
@@ -12,7 +12,7 @@ package Math::BigFloat;
# _a : accuracy
# _p : precision
-$VERSION = '1.998';
+$VERSION = '1.9991';
require 5.006002;
require Exporter;
@@ -454,7 +454,7 @@ sub bneg
return $x if $x->modify('bneg');
- # for +0 dont negate (to have always normalized +0). Does nothing for 'NaN'
+ # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN'
$x->{sign} =~ tr/+-/-+/ unless ($x->{sign} eq '+' && $MBI->_is_zero($x->{_m}));
$x;
}
@@ -1872,7 +1872,7 @@ sub bdiv
($x->{_e},$x->{_es}) = _e_sub($x->{_e}, $MBI->_new($scale), $x->{_es}, '+');
$x->bnorm(); # remove trailing 0's
}
- } # ende else $x != $y
+ } # end else $x != $y
# shortcut to not run through _find_round_parameters again
if (defined $params[0])
@@ -2037,7 +2037,7 @@ sub broot
# simulate old behaviour
$params[0] = $self->div_scale(); # and round to it as accuracy
$scale = $params[0]+4; # at least four more for proper round
- $params[2] = $r; # iound mode by caller or undef
+ $params[2] = $r; # round mode by caller or undef
$fallback = 1; # to clear a/p afterwards
}
else
@@ -3289,7 +3289,7 @@ sub bfround
my $zad = 0; # zeros after dot
$zad = $dad - $len if (-$dad < -$len); # for 0.00..00xxx style
- # p rint "scale $scale dad $dad zad $zad len $len\n";
+ # print "scale $scale dad $dad zad $zad len $len\n";
# number bsstr len zad dad
# 0.123 123e-3 3 0 3
# 0.0123 123e-4 3 1 4
@@ -3403,7 +3403,7 @@ sub bround
sub bfloor
{
- # return integer less or equal then $x
+ # round towards minus infinity
my ($self,$x,$a,$p,$r) = ref($_[0]) ? (ref($_[0]),@_) : objectify(1,@_);
return $x if $x->modify('bfloor');
@@ -3423,7 +3423,7 @@ sub bfloor
sub bceil
{
- # return integer greater or equal then $x
+ # round towards plus infinity
my ($self,$x,$a,$p,$r) = ref($_[0]) ? (ref($_[0]),@_) : objectify(1,@_);
return $x if $x->modify('bceil');
@@ -3440,6 +3440,24 @@ sub bceil
$x->round($a,$p,$r);
}
+sub bint
+ {
+ # round towards zero
+ my ($self,$x,$a,$p,$r) = ref($_[0]) ? (ref($_[0]),@_) : objectify(1,@_);
+
+ return $x if $x->modify('bint');
+ return $x if $x->{sign} !~ /^[+-]$/; # nan, +inf, -inf
+
+ # if $x has digits after the decimal point
+ if ($x->{_es} eq '-')
+ {
+ $x->{_m} = $MBI->_rsft($x->{_m},$x->{_e},10); # cut off digits after dot
+ $x->{_e} = $MBI->_zero(); # truncate/normalize
+ $x->{_es} = '+'; # abs e
+ }
+ $x->round($a,$p,$r);
+ }
+
sub brsft
{
# shift right by $y (divide by power of $n)
@@ -3695,7 +3713,7 @@ sub bnorm
if $MBI->_is_zero($x->{_m});
}
- $x; # MBI bnorm is no-op, so dont call it
+ $x; # MBI bnorm is no-op, so do not call it
}
##############################################################################
@@ -3808,6 +3826,7 @@ sub length
}
1;
+
__END__
=head1 NAME
@@ -3906,6 +3925,7 @@ Math::BigFloat - Arbitrary size floating point math package
$x->bfloor(); # return integer less or equal than $x
$x->bceil(); # return integer greater or equal than $x
+ $x->bint(); # round towards zero
# The following do not modify their arguments:
@@ -3943,12 +3963,12 @@ declare your big floating point numbers as
Operations with overloaded operators preserve the arguments, which is
exactly what you expect.
-=head2 Canonical notation
+=head2 Input
Input to these routines are either BigFloat objects, or strings of the
following four forms:
-=over 2
+=over
=item *
@@ -3996,16 +4016,16 @@ Some routines (C<is_odd()>, C<is_even()>, C<is_zero()>, C<is_one()>,
C<is_nan()>) return true or false, while others (C<bcmp()>, C<bacmp()>)
return either undef, <0, 0 or >0 and are suited for sort.
-Actual math is done by using the class defined with C<< with => Class; >> (which
-defaults to BigInts) to represent the mantissa and exponent.
+Actual math is done by using the class defined with C<< with => Class; >>
+(which defaults to BigInts) to represent the mantissa and exponent.
The sign C</^[+-]$/> is stored separately. The string 'NaN' is used to
represent the result when input arguments are not numbers, as well as
the result of dividing by zero.
-=head2 C<mantissa()>, C<exponent()> and C<parts()>
+=head2 mantissa(), exponent() and parts()
-C<mantissa()> and C<exponent()> return the said parts of the BigFloat
+mantissa() and exponent() return the said parts of the BigFloat
as BigInts such that:
$m = $x->mantissa();
@@ -4080,7 +4100,7 @@ functions like so:
=head2 Rounding
-=over 2
+=over
=item ffround ( +$scale )
@@ -4136,14 +4156,16 @@ calculates non-integer results when possible. Please see L<Math::BigInt>
for a full description of each method. Below are just the most important
differences:
-=head2 accuracy
+=over
+
+=item accuracy()
- $x->accuracy(5); # local for $x
- CLASS->accuracy(5); # global for all members of CLASS
- # Note: This also applies to new()!
+ $x->accuracy(5); # local for $x
+ CLASS->accuracy(5); # global for all members of CLASS
+ # Note: This also applies to new()!
- $A = $x->accuracy(); # read out accuracy that affects $x
- $A = CLASS->accuracy(); # read out global accuracy
+ $A = $x->accuracy(); # read out accuracy that affects $x
+ $A = CLASS->accuracy(); # read out global accuracy
Set or get the global or local accuracy, aka how many significant digits the
results have. If you set a global accuracy, then this also applies to new()!
@@ -4161,25 +4183,25 @@ to the math operation as additional parameter:
print scalar $x->copy()->bdiv($y, 2); # print 4300
print scalar $x->copy()->bdiv($y)->bround(2); # print 4300
-=head2 precision()
+=item precision()
- $x->precision(-2); # local for $x, round at the second
- # digit right of the dot
- $x->precision(2); # ditto, round at the second digit left
- # of the dot
+ $x->precision(-2); # local for $x, round at the second
+ # digit right of the dot
+ $x->precision(2); # ditto, round at the second digit
+ # left of the dot
- CLASS->precision(5); # Global for all members of CLASS
- # This also applies to new()!
- CLASS->precision(-5); # ditto
+ CLASS->precision(5); # Global for all members of CLASS
+ # This also applies to new()!
+ CLASS->precision(-5); # ditto
- $P = CLASS->precision(); # read out global precision
- $P = $x->precision(); # read out precision that affects $x
+ $P = CLASS->precision(); # read out global precision
+ $P = $x->precision(); # read out precision that affects $x
-Note: You probably want to use L</accuracy> instead. With L</accuracy> you
+Note: You probably want to use L</accuracy()> instead. With L</accuracy()> you
set the number of digits each result should have, with L</precision()> you
set the place where to round!
-=head2 bexp()
+=item bexp()
$x->bexp($accuracy); # calculate e ** X
@@ -4187,7 +4209,7 @@ Calculates the expression C<e ** $x> where C<e> is Euler's number.
This method was added in v1.82 of Math::BigInt (April 2007).
-=head2 bnok()
+=item bnok()
$x->bnok($y); # x over y (binomial coefficient n over k)
@@ -4200,7 +4222,7 @@ function. The result is equivalent to:
This method was added in v1.84 of Math::BigInt (April 2007).
-=head2 bpi()
+=item bpi()
print Math::BigFloat->bpi(100), "\n";
@@ -4209,7 +4231,7 @@ rounded according to the current rounding mode, which defaults to "even".
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bcos()
+=item bcos()
my $x = Math::BigFloat->new(1);
print $x->bcos(100), "\n";
@@ -4218,7 +4240,7 @@ Calculate the cosinus of $x, modifying $x in place.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bsin()
+=item bsin()
my $x = Math::BigFloat->new(1);
print $x->bsin(100), "\n";
@@ -4227,7 +4249,7 @@ Calculate the sinus of $x, modifying $x in place.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan2()
+=item batan2()
my $y = Math::BigFloat->new(2);
my $x = Math::BigFloat->new(3);
@@ -4238,7 +4260,7 @@ See also L</batan()>.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan()
+=item batan()
my $x = Math::BigFloat->new(1);
print $x->batan(100), "\n";
@@ -4247,7 +4269,7 @@ Calculate the arcus tanges of $x, modifying $x in place. See also L</batan2()>.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bmuladd()
+=item bmuladd()
$x->bmuladd($y,$z);
@@ -4255,6 +4277,8 @@ Multiply $x by $y, and then add $z to the result.
This method was added in v1.87 of Math::BigInt (June 2007).
+=back
+
=head1 Autocreating constants
After C<use Math::BigFloat ':constant'> all the floating point constants
@@ -4363,7 +4387,7 @@ and B<VERY BAD THINGS> will happen when you use these together:
my $flash_and_bang = $matter + $anti_matter; # Don't do this!
-=over 1
+=over
=item stringify, bstr()
@@ -4371,7 +4395,7 @@ Both stringify and bstr() now drop the leading '+'. The old code would return
'+1.23', the new returns '1.23'. See the documentation in L<Math::BigInt> for
reasoning and details.
-=item bdiv
+=item bdiv()
The following will probably not print what you expect:
@@ -4381,11 +4405,12 @@ It prints both quotient and remainder since print works in list context. Also,
bdiv() will modify $c, so be careful. You probably want to use
print $c / 123.456,"\n";
- print scalar $c->bdiv(123.456),"\n"; # or if you want to modify $c
+ # or if you want to modify $c:
+ print scalar $c->bdiv(123.456),"\n";
instead.
-=item brsft
+=item brsft()
The following will probably not print what you expect:
@@ -4414,7 +4439,7 @@ a second reference to the B<same> object and stores it in $y. Thus anything
that modifies $x will modify $y (except overloaded math operators), and vice
versa. See L<Math::BigInt> for details and how to avoid that.
-=item bpow
+=item bpow()
C<bpow()> now modifies the first argument, unlike the old code which left
it alone and only returned the result. This is to be consistent with
@@ -4431,39 +4456,39 @@ a certain number of digits:
use Math::BigFloat;
- Math::BigFloat->precision(4); # does not do what you
- # think it does
- my $x = Math::BigFloat->new(12345); # rounds $x to "12000"!
- print "$x\n"; # print "12000"
- my $y = Math::BigFloat->new(3); # rounds $y to "0"!
- print "$y\n"; # print "0"
- $z = $x / $y; # 12000 / 0 => NaN!
+ Math::BigFloat->precision(4); # does not do what you
+ # think it does
+ my $x = Math::BigFloat->new(12345); # rounds $x to "12000"!
+ print "$x\n"; # print "12000"
+ my $y = Math::BigFloat->new(3); # rounds $y to "0"!
+ print "$y\n"; # print "0"
+ $z = $x / $y; # 12000 / 0 => NaN!
print "$z\n";
- print $z->precision(),"\n"; # 4
+ print $z->precision(),"\n"; # 4
-Replacing L</precision()> with L</accuracy> is probably not what you want, either:
+Replacing L</precision()> with L</accuracy()> is probably not what you want, either:
use Math::BigFloat;
- Math::BigFloat->accuracy(4); # enables global rounding:
- my $x = Math::BigFloat->new(123456); # rounded immediately
- # to "12350"
- print "$x\n"; # print "123500"
- my $y = Math::BigFloat->new(3); # rounded to "3
- print "$y\n"; # print "3"
- print $z = $x->copy()->bdiv($y),"\n"; # 41170
- print $z->accuracy(),"\n"; # 4
+ Math::BigFloat->accuracy(4); # enables global rounding:
+ my $x = Math::BigFloat->new(123456); # rounded immediately
+ # to "12350"
+ print "$x\n"; # print "123500"
+ my $y = Math::BigFloat->new(3); # rounded to "3
+ print "$y\n"; # print "3"
+ print $z = $x->copy()->bdiv($y),"\n"; # 41170
+ print $z->accuracy(),"\n"; # 4
What you want to use instead is:
use Math::BigFloat;
- my $x = Math::BigFloat->new(123456); # no rounding
- print "$x\n"; # print "123456"
- my $y = Math::BigFloat->new(3); # no rounding
- print "$y\n"; # print "3"
- print $z = $x->copy()->bdiv($y,4),"\n"; # 41150
- print $z->accuracy(),"\n"; # undef
+ my $x = Math::BigFloat->new(123456); # no rounding
+ print "$x\n"; # print "123456"
+ my $y = Math::BigFloat->new(3); # no rounding
+ print "$y\n"; # print "3"
+ print $z = $x->copy()->bdiv($y,4),"\n"; # 41150
+ print $z->accuracy(),"\n"; # undef
In addition to computing what you expected, the last example also does B<not>
"taint" the result with an accuracy or precision setting, which would
diff --git a/Master/tlpkg/tlperl/lib/Math/BigFloat/Trace.pm b/Master/tlpkg/tlperl/lib/Math/BigFloat/Trace.pm
index d712082eb6a..203e0510b64 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigFloat/Trace.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigFloat/Trace.pm
@@ -12,7 +12,7 @@ use vars qw($VERSION @ISA $PACKAGE @EXPORT_OK
@ISA = qw(Exporter Math::BigFloat);
-$VERSION = '0.32';
+$VERSION = '0.36';
use overload; # inherit overload from BigFloat
diff --git a/Master/tlpkg/tlperl/lib/Math/BigInt.pm b/Master/tlpkg/tlperl/lib/Math/BigInt.pm
index 37c6b37a987..eff27b95a97 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigInt.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigInt.pm
@@ -18,7 +18,7 @@ package Math::BigInt;
my $class = "Math::BigInt";
use 5.006002;
-$VERSION = '1.9991';
+$VERSION = '1.9993';
@ISA = qw(Exporter);
@EXPORT_OK = qw(objectify bgcd blcm);
@@ -149,7 +149,7 @@ use overload
},
# the original qw() does not work with the TIESCALAR below, why?
-# Order of arguments unsignificant
+# Order of arguments insignificant
'""' => sub { $_[0]->bstr(); },
'0+' => sub { $_[0]->numify(); }
;
@@ -1036,7 +1036,7 @@ sub bneg
return $x if $x->modify('bneg');
- # for +0 dont negate (to have always normalized +0). Does nothing for 'NaN'
+ # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN'
$x->{sign} =~ tr/+-/-+/ unless ($x->{sign} eq '+' && $CALC->_is_zero($x->{value}));
$x;
}
@@ -1073,7 +1073,7 @@ sub bcmp
return -1 if $x->{sign} eq '-' && $y->{sign} eq '+'; # does also -x <=> 0
# have same sign, so compare absolute values. Don't make tests for zero here
- # because it's actually slower than testin in Calc (especially w/ Pari et al)
+ # because it's actually slower than testing in Calc (especially w/ Pari et al)
# post-normalized compare for internal use (honors signs)
if ($x->{sign} eq '+')
@@ -1083,7 +1083,7 @@ sub bcmp
}
# $x && $y both < 0
- $CALC->_acmp($y->{value},$x->{value}); # swaped acmp (lib returns 0,1,-1)
+ $CALC->_acmp($y->{value},$x->{value}); # swapped acmp (lib returns 0,1,-1)
}
sub bacmp
@@ -1740,7 +1740,7 @@ sub bdiv
}
else
{
- $rem->{sign} = '+'; # dont leave -0
+ $rem->{sign} = '+'; # do not leave -0
}
$rem->round(@r);
return ($x,$rem);
@@ -1788,7 +1788,7 @@ sub bmod
}
else
{
- $x->{sign} = '+'; # dont leave -0
+ $x->{sign} = '+'; # do not leave -0
}
$x->round(@r);
}
@@ -2533,7 +2533,7 @@ sub bround
sub bfloor
{
- # return integer less or equal then number; no-op since it's already integer
+ # round towards minus infinity; no-op since it's already integer
my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
$x->round(@r);
@@ -2541,12 +2541,19 @@ sub bfloor
sub bceil
{
- # return integer greater or equal then number; no-op since it's already int
+ # round towards plus infinity; no-op since it's already int
my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
$x->round(@r);
}
+sub bint {
+ # round towards zero; no-op since it's already integer
+ my ($self,$x,@r) = ref($_[0]) ? (undef,@_) : objectify(1,@_);
+
+ $x->round(@r);
+}
+
sub as_number
{
# An object might be asked to return itself as bigint on certain overloaded
@@ -3375,33 +3382,33 @@ Math::BigInt - Arbitrary size integer/float math package
$x->bmuladd($y,$z); # $x = $x * $y + $z
- $x->bmod($y); # modulus (x % y)
- $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod)
- $x->bmodinv($mod); # modular multiplicative inverse
- $x->bpow($y); # power of arguments (x ** y)
- $x->blsft($y); # left shift in base 2
- $x->brsft($y); # right shift in base 2
- # returns (quo,rem) or quo if in sca-
- # lar context
- $x->blsft($y,$n); # left shift by $y places in base $n
- $x->brsft($y,$n); # right shift by $y places in base $n
- # returns (quo,rem) or quo if in sca-
- # lar context
-
- $x->band($y); # bitwise and
- $x->bior($y); # bitwise inclusive or
- $x->bxor($y); # bitwise exclusive or
- $x->bnot(); # bitwise not (two's complement)
-
- $x->bsqrt(); # calculate square-root
- $x->broot($y); # $y'th root of $x (e.g. $y == 3 => cubic root)
- $x->bfac(); # factorial of $x (1*2*3*4*..$x)
-
- $x->bnok($y); # x over y (binomial coefficient n over k)
-
- $x->blog(); # logarithm of $x to base e (Euler's number)
- $x->blog($base); # logarithm of $x to base $base (f.i. 2)
- $x->bexp(); # calculate e ** $x where e is Euler's number
+ $x->bmod($y); # modulus (x % y)
+ $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod)
+ $x->bmodinv($mod); # modular multiplicative inverse
+ $x->bpow($y); # power of arguments (x ** y)
+ $x->blsft($y); # left shift in base 2
+ $x->brsft($y); # right shift in base 2
+ # returns (quo,rem) or quo if in sca-
+ # lar context
+ $x->blsft($y,$n); # left shift by $y places in base $n
+ $x->brsft($y,$n); # right shift by $y places in base $n
+ # returns (quo,rem) or quo if in sca-
+ # lar context
+
+ $x->band($y); # bitwise and
+ $x->bior($y); # bitwise inclusive or
+ $x->bxor($y); # bitwise exclusive or
+ $x->bnot(); # bitwise not (two's complement)
+
+ $x->bsqrt(); # calculate square-root
+ $x->broot($y); # $y'th root of $x (e.g. $y == 3 => cubic root)
+ $x->bfac(); # factorial of $x (1*2*3*4*..$x)
+
+ $x->bnok($y); # x over y (binomial coefficient n over k)
+
+ $x->blog(); # logarithm of $x to base e (Euler's number)
+ $x->blog($base); # logarithm of $x to base $base (f.i. 2)
+ $x->bexp(); # calculate e ** $x where e is Euler's number
$x->round($A,$P,$mode); # round to accuracy or precision using
# mode $mode
@@ -3413,8 +3420,9 @@ Math::BigInt - Arbitrary size integer/float math package
# The following do not modify their arguments in BigInt (are no-ops),
# but do so in BigFloat:
- $x->bfloor(); # return integer less or equal than $x
- $x->bceil(); # return integer greater or equal than $x
+ $x->bfloor(); # round towards minus infinity
+ $x->bceil(); # round towards plus infinity
+ $x->bint(); # round towards zero
# The following do not modify their arguments:
@@ -3467,9 +3475,7 @@ declare your big integers as
Operations with overloaded operators preserve the arguments which is
exactly what you expect.
-=over 2
-
-=item Input
+=head2 Input
Input values to these routines may be any string, that looks like a number
and results in an integer, including hexadecimal and binary numbers.
@@ -3507,7 +3513,7 @@ C<bnorm()> on a BigInt object is now effectively a no-op, since the numbers
are always stored in normalized form. If passed a string, creates a BigInt
object from the input.
-=item Output
+=head2 Output
Output values are BigInt objects (normalized), except for the methods which
return a string (see L</SYNOPSIS>).
@@ -3516,8 +3522,6 @@ Some routines (C<is_odd()>, C<is_even()>, C<is_zero()>, C<is_one()>,
C<is_nan()>, etc.) return true or false, while others (C<bcmp()>, C<bacmp()>)
return either undef (if NaN is involved), <0, 0 or >0 and are suited for sort.
-=back
-
=head1 METHODS
Each of the methods below (except config(), accuracy() and precision())
@@ -3525,44 +3529,46 @@ accepts three additional parameters. These arguments C<$A>, C<$P> and C<$R>
are C<accuracy>, C<precision> and C<round_mode>. Please see the section about
L</ACCURACY and PRECISION> for more information.
-=head2 config()
+=over
+
+=item config()
- use Data::Dumper;
+ use Data::Dumper;
- print Dumper ( Math::BigInt->config() );
- print Math::BigInt->config()->{lib},"\n";
+ print Dumper ( Math::BigInt->config() );
+ print Math::BigInt->config()->{lib},"\n";
Returns a hash containing the configuration, e.g. the version number, lib
loaded etc. The following hash keys are currently filled in with the
appropriate information.
- key Description
- Example
- ============================================================
- lib Name of the low-level math library
- Math::BigInt::Calc
- lib_version Version of low-level math library (see 'lib')
- 0.30
- class The class name of config() you just called
- Math::BigInt
- upgrade To which class math operations might be upgraded
- Math::BigFloat
- downgrade To which class math operations might be downgraded
- undef
- precision Global precision
- undef
- accuracy Global accuracy
- undef
- round_mode Global round mode
- even
- version version number of the class you used
- 1.61
- div_scale Fallback accuracy for div
- 40
- trap_nan If true, traps creation of NaN via croak()
- 1
- trap_inf If true, traps creation of +inf/-inf via croak()
- 1
+ key Description
+ Example
+ ============================================================
+ lib Name of the low-level math library
+ Math::BigInt::Calc
+ lib_version Version of low-level math library (see 'lib')
+ 0.30
+ class The class name of config() you just called
+ Math::BigInt
+ upgrade To which class math operations might be
+ upgraded Math::BigFloat
+ downgrade To which class math operations might be
+ downgraded undef
+ precision Global precision
+ undef
+ accuracy Global accuracy
+ undef
+ round_mode Global round mode
+ even
+ version version number of the class you used
+ 1.61
+ div_scale Fallback accuracy for div
+ 40
+ trap_nan If true, traps creation of NaN via croak()
+ 1
+ trap_inf If true, traps creation of +inf/-inf via croak()
+ 1
The following values can be set by passing C<config()> a reference to a hash:
@@ -3575,7 +3581,7 @@ Example:
{ trap_inf => 1, precision => 5 }
);
-=head2 accuracy()
+=item accuracy()
$x->accuracy(5); # local for $x
CLASS->accuracy(5); # global for all members of CLASS
@@ -3617,7 +3623,8 @@ represents the accuracy that will be in effect for $x:
# ally rounded!
print "$x $y\n"; # '123500 1234567'
print $x->accuracy(),"\n"; # will be 4
- print $y->accuracy(),"\n"; # also 4, since global is 4
+ print $y->accuracy(),"\n"; # also 4, since
+ # global is 4
print Math::BigInt->accuracy(5),"\n"; # set to 5, print 5
print $x->accuracy(),"\n"; # still 4
print $y->accuracy(),"\n"; # 5, since global is 5
@@ -3627,19 +3634,19 @@ globals separated from Math::BigInt, but it is possible to subclass
Math::BigInt and make the globals of the subclass aliases to the ones from
Math::BigInt.
-=head2 precision()
+=item precision()
- $x->precision(-2); # local for $x, round at the second
- # digit right of the dot
- $x->precision(2); # ditto, round at the second digit left
- # of the dot
+ $x->precision(-2); # local for $x, round at the second
+ # digit right of the dot
+ $x->precision(2); # ditto, round at the second digit
+ # left of the dot
- CLASS->precision(5); # Global for all members of CLASS
- # This also applies to new()!
- CLASS->precision(-5); # ditto
+ CLASS->precision(5); # Global for all members of CLASS
+ # This also applies to new()!
+ CLASS->precision(-5); # ditto
- $P = CLASS->precision(); # read out global precision
- $P = $x->precision(); # read out precision that affects $x
+ $P = CLASS->precision(); # read out global precision
+ $P = $x->precision(); # read out precision that affects $x
Note: You probably want to use L</accuracy()> instead. With L</accuracy()> you
set the number of digits each result should have, with L</precision()> you
@@ -3666,7 +3673,7 @@ value represents the prevision that will be in effect for $x:
$y = Math::BigInt->new(1234567); # unrounded
print Math::BigInt->precision(4),"\n"; # set 4, print 4
- $x = Math::BigInt->new(123456); # will be automatically rounded
+ $x = Math::BigInt->new(123456); # will be automatically rounded
print $x; # print "120000"!
Note: Works also for subclasses like L<Math::BigFloat>. Each class has its
@@ -3674,9 +3681,9 @@ own globals separated from Math::BigInt, but it is possible to subclass
Math::BigInt and make the globals of the subclass aliases to the ones from
Math::BigInt.
-=head2 brsft()
+=item brsft()
- $x->brsft($y,$n);
+ $x->brsft($y,$n);
Shifts $x right by $y in base $n. Default is base 2, used are usually 10 and
2, but others work, too.
@@ -3685,23 +3692,23 @@ Right shifting usually amounts to dividing $x by $n ** $y and truncating the
result:
- $x = Math::BigInt->new(10);
- $x->brsft(1); # same as $x >> 1: 5
- $x = Math::BigInt->new(1234);
- $x->brsft(2,10); # result 12
+ $x = Math::BigInt->new(10);
+ $x->brsft(1); # same as $x >> 1: 5
+ $x = Math::BigInt->new(1234);
+ $x->brsft(2,10); # result 12
There is one exception, and that is base 2 with negative $x:
- $x = Math::BigInt->new(-5);
- print $x->brsft(1);
+ $x = Math::BigInt->new(-5);
+ print $x->brsft(1);
This will print -3, not -2 (as it would if you divide -5 by 2 and truncate the
result).
-=head2 new()
+=item new()
- $x = Math::BigInt->new($str,$A,$P,$R);
+ $x = Math::BigInt->new($str,$A,$P,$R);
Creates a new BigInt object from a scalar or another BigInt object. The
input is accepted as decimal, hex (with leading '0x') or binary (with leading
@@ -3709,90 +3716,90 @@ input is accepted as decimal, hex (with leading '0x') or binary (with leading
See L</Input> for more info on accepted input formats.
-=head2 from_oct()
+=item from_oct()
- $x = Math::BigInt->from_oct("0775"); # input is octal
+ $x = Math::BigInt->from_oct("0775"); # input is octal
Interpret the input as an octal string and return the corresponding value. A
"0" (zero) 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.
-=head2 from_hex()
+=item from_hex()
- $x = Math::BigInt->from_hex("0xcafe"); # input is hexadecimal
+ $x = Math::BigInt->from_hex("0xcafe"); # input is hexadecimal
Interpret input as a hexadecimal string. A "0x" or "x" 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.
-=head2 from_bin()
+=item from_bin()
- $x = Math::BigInt->from_bin("0b10011"); # input is binary
+ $x = Math::BigInt->from_bin("0b10011"); # input is binary
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.
-=head2 bnan()
+=item bnan()
- $x = Math::BigInt->bnan();
+ $x = Math::BigInt->bnan();
Creates a new BigInt object representing NaN (Not A Number).
If used on an object, it will set it to NaN:
- $x->bnan();
+ $x->bnan();
-=head2 bzero()
+=item bzero()
- $x = Math::BigInt->bzero();
+ $x = Math::BigInt->bzero();
Creates a new BigInt object representing zero.
If used on an object, it will set it to zero:
- $x->bzero();
+ $x->bzero();
-=head2 binf()
+=item binf()
- $x = Math::BigInt->binf($sign);
+ $x = Math::BigInt->binf($sign);
Creates a new BigInt object representing infinity. The optional argument is
either '-' or '+', indicating whether you want infinity or minus infinity.
If used on an object, it will set it to infinity:
- $x->binf();
- $x->binf('-');
+ $x->binf();
+ $x->binf('-');
-=head2 bone()
+=item bone()
- $x = Math::BigInt->binf($sign);
+ $x = Math::BigInt->binf($sign);
Creates a new BigInt object representing one. The optional argument is
either '-' or '+', indicating whether you want one or minus one.
If used on an object, it will set it to one:
- $x->bone(); # +1
- $x->bone('-'); # -1
+ $x->bone(); # +1
+ $x->bone('-'); # -1
-=head2 is_one()/is_zero()/is_nan()/is_inf()
+=item is_one()/is_zero()/is_nan()/is_inf()
- $x->is_zero(); # true if arg is +0
- $x->is_nan(); # true if arg is NaN
- $x->is_one(); # true if arg is +1
- $x->is_one('-'); # true if arg is -1
- $x->is_inf(); # true if +inf
- $x->is_inf('-'); # true if -inf (sign is default '+')
+ $x->is_zero(); # true if arg is +0
+ $x->is_nan(); # true if arg is NaN
+ $x->is_one(); # true if arg is +1
+ $x->is_one('-'); # true if arg is -1
+ $x->is_inf(); # true if +inf
+ $x->is_inf('-'); # true if -inf (sign is default '+')
These methods all test the BigInt for being one specific value and return
true or false depending on the input. These are faster than doing something
like:
- if ($x == 0)
+ if ($x == 0)
-=head2 is_pos()/is_neg()/is_positive()/is_negative()
+=item is_pos()/is_neg()/is_positive()/is_negative()
- $x->is_pos(); # true if > 0
- $x->is_neg(); # true if < 0
+ $x->is_pos(); # true if > 0
+ $x->is_neg(); # true if < 0
The methods return true if the argument is positive or negative, respectively.
C<NaN> is neither positive nor negative, while C<+inf> counts as positive, and
@@ -3805,177 +3812,177 @@ C<is_neg()>, respectively. C<is_positive()> and C<is_negative()> were
introduced in v1.36, while C<is_pos()> and C<is_neg()> were only introduced
in v1.68.
-=head2 is_odd()/is_even()/is_int()
+=item is_odd()/is_even()/is_int()
- $x->is_odd(); # true if odd, false for even
- $x->is_even(); # true if even, false for odd
- $x->is_int(); # true if $x is an integer
+ $x->is_odd(); # true if odd, false for even
+ $x->is_even(); # true if even, false for odd
+ $x->is_int(); # true if $x is an integer
The return true when the argument satisfies the condition. C<NaN>, C<+inf>,
C<-inf> are not integers and are neither odd nor even.
In BigInt, all numbers except C<NaN>, C<+inf> and C<-inf> are integers.
-=head2 bcmp()
+=item bcmp()
- $x->bcmp($y);
+ $x->bcmp($y);
Compares $x with $y and takes the sign into account.
Returns -1, 0, 1 or undef.
-=head2 bacmp()
+=item bacmp()
- $x->bacmp($y);
+ $x->bacmp($y);
Compares $x with $y while ignoring their sign. Returns -1, 0, 1 or undef.
-=head2 sign()
+=item sign()
- $x->sign();
+ $x->sign();
Return the sign, of $x, meaning either C<+>, C<->, C<-inf>, C<+inf> or NaN.
If you want $x to have a certain sign, use one of the following methods:
- $x->babs(); # '+'
- $x->babs()->bneg(); # '-'
- $x->bnan(); # 'NaN'
- $x->binf(); # '+inf'
- $x->binf('-'); # '-inf'
+ $x->babs(); # '+'
+ $x->babs()->bneg(); # '-'
+ $x->bnan(); # 'NaN'
+ $x->binf(); # '+inf'
+ $x->binf('-'); # '-inf'
-=head2 digit()
+=item digit()
- $x->digit($n); # return the nth digit, counting from right
+ $x->digit($n); # return the nth digit, counting from right
If C<$n> is negative, returns the digit counting from left.
-=head2 bneg()
+=item bneg()
- $x->bneg();
+ $x->bneg();
Negate the number, e.g. change the sign between '+' and '-', or between '+inf'
and '-inf', respectively. Does nothing for NaN or zero.
-=head2 babs()
+=item babs()
- $x->babs();
+ $x->babs();
Set the number to its absolute value, e.g. change the sign from '-' to '+'
and from '-inf' to '+inf', respectively. Does nothing for NaN or positive
numbers.
-=head2 bsgn()
+=item bsgn()
- $x->bsgn();
+ $x->bsgn();
Signum function. Set the number to -1, 0, or 1, depending on whether the
-number is negative, zero, or positive, respectivly. Does not modify NaNs.
+number is negative, zero, or positive, respectively. Does not modify NaNs.
-=head2 bnorm()
+=item bnorm()
- $x->bnorm(); # normalize (no-op)
+ $x->bnorm(); # normalize (no-op)
-=head2 bnot()
+=item bnot()
- $x->bnot();
+ $x->bnot();
Two's complement (bitwise not). This is equivalent to
- $x->binc()->bneg();
+ $x->binc()->bneg();
but faster.
-=head2 binc()
+=item binc()
- $x->binc(); # increment x by 1
+ $x->binc(); # increment x by 1
-=head2 bdec()
+=item bdec()
- $x->bdec(); # decrement x by 1
+ $x->bdec(); # decrement x by 1
-=head2 badd()
+=item badd()
- $x->badd($y); # addition (add $y to $x)
+ $x->badd($y); # addition (add $y to $x)
-=head2 bsub()
+=item bsub()
- $x->bsub($y); # subtraction (subtract $y from $x)
+ $x->bsub($y); # subtraction (subtract $y from $x)
-=head2 bmul()
+=item bmul()
- $x->bmul($y); # multiplication (multiply $x by $y)
+ $x->bmul($y); # multiplication (multiply $x by $y)
-=head2 bmuladd()
+=item bmuladd()
- $x->bmuladd($y,$z);
+ $x->bmuladd($y,$z);
Multiply $x by $y, and then add $z to the result,
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bdiv()
+=item bdiv()
- $x->bdiv($y); # divide, set $x to quotient
+ $x->bdiv($y); # divide, set $x to quotient
# return (quo,rem) or quo if scalar
-=head2 bmod()
+=item bmod()
- $x->bmod($y); # modulus (x % y)
+ $x->bmod($y); # modulus (x % y)
-=head2 bmodinv()
+=item bmodinv()
- $x->bmodinv($mod); # modular multiplicative inverse
+ $x->bmodinv($mod); # modular multiplicative inverse
Returns the multiplicative inverse of C<$x> modulo C<$mod>. If
- $y = $x -> copy() -> bmodinv($mod)
+ $y = $x -> copy() -> bmodinv($mod)
then C<$y> is the number closest to zero, and with the same sign as C<$mod>,
satisfying
- ($x * $y) % $mod = 1 % $mod
+ ($x * $y) % $mod = 1 % $mod
If C<$x> and C<$y> are non-zero, they must be relative primes, i.e.,
C<bgcd($y, $mod)==1>. 'C<NaN>' is returned when no modular multiplicative
inverse exists.
-=head2 bmodpow()
+=item bmodpow()
- $num->bmodpow($exp,$mod); # modular exponentiation
+ $num->bmodpow($exp,$mod); # modular exponentiation
# ($num**$exp % $mod)
Returns the value of C<$num> taken to the power C<$exp> in the modulus
C<$mod> using binary exponentiation. C<bmodpow> is far superior to
writing
- $num ** $exp % $mod
+ $num ** $exp % $mod
because it is much faster - it reduces internal variables into
the modulus whenever possible, so it operates on smaller numbers.
C<bmodpow> also supports negative exponents.
- bmodpow($num, -1, $mod)
+ bmodpow($num, -1, $mod)
is exactly equivalent to
- bmodinv($num, $mod)
+ bmodinv($num, $mod)
-=head2 bpow()
+=item bpow()
- $x->bpow($y); # power of arguments (x ** y)
+ $x->bpow($y); # power of arguments (x ** y)
-=head2 blog()
+=item blog()
- $x->blog($base, $accuracy); # logarithm of x to the base $base
+ $x->blog($base, $accuracy); # logarithm of x to the base $base
If C<$base> is not defined, Euler's number (e) is used:
- print $x->blog(undef, 100); # log(x) to 100 digits
+ print $x->blog(undef, 100); # log(x) to 100 digits
-=head2 bexp()
+=item bexp()
- $x->bexp($accuracy); # calculate e ** X
+ $x->bexp($accuracy); # calculate e ** X
Calculates the expression C<e ** $x> where C<e> is Euler's number.
@@ -3983,9 +3990,9 @@ This method was added in v1.82 of Math::BigInt (April 2007).
See also L</blog()>.
-=head2 bnok()
+=item bnok()
- $x->bnok($y); # x over y (binomial coefficient n over k)
+ $x->bnok($y); # x over y (binomial coefficient n over k)
Calculates the binomial coefficient n over k, also called the "choose"
function. The result is equivalent to:
@@ -3996,9 +4003,9 @@ function. The result is equivalent to:
This method was added in v1.84 of Math::BigInt (April 2007).
-=head2 bpi()
+=item bpi()
- print Math::BigInt->bpi(100), "\n"; # 3
+ print Math::BigInt->bpi(100), "\n"; # 3
Returns PI truncated to an integer, with the argument being ignored. This means
under BigInt this always returns C<3>.
@@ -4006,17 +4013,17 @@ under BigInt this always returns C<3>.
If upgrading is in effect, returns PI, rounded to N digits with the
current rounding mode:
- use Math::BigFloat;
- use Math::BigInt upgrade => Math::BigFloat;
- print Math::BigInt->bpi(3), "\n"; # 3.14
- print Math::BigInt->bpi(100), "\n"; # 3.1415....
+ use Math::BigFloat;
+ use Math::BigInt upgrade => Math::BigFloat;
+ print Math::BigInt->bpi(3), "\n"; # 3.14
+ print Math::BigInt->bpi(100), "\n"; # 3.1415....
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bcos()
+=item bcos()
- my $x = Math::BigInt->new(1);
- print $x->bcos(100), "\n";
+ my $x = Math::BigInt->new(1);
+ print $x->bcos(100), "\n";
Calculate the cosinus of $x, modifying $x in place.
@@ -4025,10 +4032,10 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 bsin()
+=item bsin()
- my $x = Math::BigInt->new(1);
- print $x->bsin(100), "\n";
+ my $x = Math::BigInt->new(1);
+ print $x->bsin(100), "\n";
Calculate the sinus of $x, modifying $x in place.
@@ -4037,11 +4044,11 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan2()
+=item batan2()
- my $x = Math::BigInt->new(1);
- my $y = Math::BigInt->new(1);
- print $y->batan2($x), "\n";
+ my $x = Math::BigInt->new(1);
+ my $y = Math::BigInt->new(1);
+ print $y->batan2($x), "\n";
Calculate the arcus tangens of C<$y> divided by C<$x>, modifying $y in place.
@@ -4050,10 +4057,10 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 batan()
+=item batan()
- my $x = Math::BigFloat->new(0.5);
- print $x->batan(100), "\n";
+ my $x = Math::BigFloat->new(0.5);
+ print $x->batan(100), "\n";
Calculate the arcus tangens of $x, modifying $x in place.
@@ -4062,60 +4069,60 @@ integer.
This method was added in v1.87 of Math::BigInt (June 2007).
-=head2 blsft()
+=item blsft()
- $x->blsft($y); # left shift in base 2
- $x->blsft($y,$n); # left shift, in base $n (like 10)
+ $x->blsft($y); # left shift in base 2
+ $x->blsft($y,$n); # left shift, in base $n (like 10)
-=head2 brsft()
+=item brsft()
- $x->brsft($y); # right shift in base 2
- $x->brsft($y,$n); # right shift, in base $n (like 10)
+ $x->brsft($y); # right shift in base 2
+ $x->brsft($y,$n); # right shift, in base $n (like 10)
-=head2 band()
+=item band()
- $x->band($y); # bitwise and
+ $x->band($y); # bitwise and
-=head2 bior()
+=item bior()
- $x->bior($y); # bitwise inclusive or
+ $x->bior($y); # bitwise inclusive or
-=head2 bxor()
+=item bxor()
- $x->bxor($y); # bitwise exclusive or
+ $x->bxor($y); # bitwise exclusive or
-=head2 bnot()
+=item bnot()
- $x->bnot(); # bitwise not (two's complement)
+ $x->bnot(); # bitwise not (two's complement)
-=head2 bsqrt()
+=item bsqrt()
- $x->bsqrt(); # calculate square-root
+ $x->bsqrt(); # calculate square-root
-=head2 broot()
+=item broot()
- $x->broot($N);
+ $x->broot($N);
Calculates the N'th root of C<$x>.
-=head2 bfac()
+=item bfac()
- $x->bfac(); # factorial of $x (1*2*3*4*..$x)
+ $x->bfac(); # factorial of $x (1*2*3*4*..$x)
-=head2 round()
+=item round()
- $x->round($A,$P,$round_mode);
+ $x->round($A,$P,$round_mode);
Round $x to accuracy C<$A> or precision C<$P> using the round mode
C<$round_mode>.
-=head2 bround()
+=item bround()
- $x->bround($N); # accuracy: preserve $N digits
+ $x->bround($N); # accuracy: preserve $N digits
-=head2 bfround()
+=item bfround()
- $x->bfround($N);
+ $x->bfround($N);
If N is > 0, rounds to the Nth digit from the left. If N < 0, rounds to
the Nth digit after the dot. Since BigInts are integers, the case N < 0
@@ -4130,60 +4137,69 @@ Examples:
123456.123456 -2 123456.12
123456.123456 -3 123456.123
-=head2 bfloor()
+=item bfloor()
+
+ $x->bfloor();
- $x->bfloor();
+Round $x towards minus infinity (i.e., set $x to the largest integer less than
+or equal to $x). This is a no-op in BigInt, but changes $x in BigFloat, if $x
+is not an integer.
-Set $x to the integer less or equal than $x. This is a no-op in BigInt, but
-does change $x in BigFloat.
+=item bceil()
-=head2 bceil()
+ $x->bceil();
- $x->bceil();
+Round $x towards plus infinity (i.e., set $x to the smallest integer greater
+than or equal to $x). This is a no-op in BigInt, but changes $x in BigFloat, if
+$x is not an integer.
-Set $x to the integer greater or equal than $x. This is a no-op in BigInt, but
-does change $x in BigFloat.
+=item bint()
-=head2 bgcd()
+ $x->bint();
- bgcd(@values); # greatest common divisor (no OO style)
+Round $x towards zero. This is a no-op in BigInt, but changes $x in BigFloat,
+if $x is not an integer.
-=head2 blcm()
+=item bgcd()
- blcm(@values); # lowest common multiple (no OO style)
+ bgcd(@values); # greatest common divisor (no OO style)
-head2 length()
+=item blcm()
- $x->length();
- ($xl,$fl) = $x->length();
+ blcm(@values); # lowest common multiple (no OO style)
+
+=item length()
+
+ $x->length();
+ ($xl,$fl) = $x->length();
Returns the number of digits in the decimal representation of the number.
In list context, returns the length of the integer and fraction part. For
BigInt's, the length of the fraction part will always be 0.
-=head2 exponent()
+=item exponent()
- $x->exponent();
+ $x->exponent();
Return the exponent of $x as BigInt.
-=head2 mantissa()
+=item mantissa()
- $x->mantissa();
+ $x->mantissa();
Return the signed mantissa of $x as BigInt.
-=head2 parts()
+=item parts()
- $x->parts(); # return (mantissa,exponent) as BigInt
+ $x->parts(); # return (mantissa,exponent) as BigInt
-=head2 copy()
+=item copy()
- $x->copy(); # make a true copy of $x (unlike $y = $x;)
+ $x->copy(); # make a true copy of $x (unlike $y = $x;)
-=head2 as_int()/as_number()
+=item as_int()/as_number()
- $x->as_int();
+ $x->as_int();
Returns $x as a BigInt (truncated towards zero). In BigInt this is the same as
C<copy()>.
@@ -4191,29 +4207,29 @@ C<copy()>.
C<as_number()> is an alias to this method. C<as_number> was introduced in
v1.22, while C<as_int()> was only introduced in v1.68.
-=head2 bstr()
+=item bstr()
- $x->bstr();
+ $x->bstr();
Returns a normalized string representation of C<$x>.
-=head2 bsstr()
+=item bsstr()
- $x->bsstr(); # normalized string in scientific notation
+ $x->bsstr(); # normalized string in scientific notation
-=head2 as_hex()
+=item as_hex()
- $x->as_hex(); # as signed hexadecimal string with prefixed 0x
+ $x->as_hex(); # as signed hexadecimal string with prefixed 0x
-=head2 as_bin()
+=item as_bin()
- $x->as_bin(); # as signed binary string with prefixed 0b
+ $x->as_bin(); # as signed binary string with prefixed 0b
-=head2 as_oct()
+=item as_oct()
- $x->as_oct(); # as signed octal string with prefixed 0
+ $x->as_oct(); # as signed octal string with prefixed 0
-=head2 numify()
+=item numify()
print $x->numify();
@@ -4222,16 +4238,16 @@ whenever a scalar is needed, for instance in array index operations.
This loses precision, to avoid this use L<as_int()|/"as_int()/as_number()"> instead.
-=head2 modify()
+=item modify()
- $x->modify('bpowd');
+ $x->modify('bpowd');
This method returns 0 if the object can be modified with the given
operation, or 1 if not.
This is used for instance by L<Math::BigInt::Constant>.
-=head2 upgrade()/downgrade()
+=item upgrade()/downgrade()
Set/get the class for downgrade/upgrade operations. Thuis is used
for instance by L<bignum>. The defaults are '', thus the following
@@ -4242,15 +4258,17 @@ operation will create a BigInt, not a BigFloat:
print $i + $f,"\n"; # print 246
-=head2 div_scale()
+=item div_scale()
Set/get the number of digits for the default precision in divide
operations.
-=head2 round_mode()
+=item round_mode()
Set/get the current round mode.
+=back
+
=head1 ACCURACY and PRECISION
Since version v1.33, Math::BigInt and Math::BigFloat have full support for
@@ -4323,7 +4341,7 @@ When rounding a number, different 'styles' or 'kinds'
of rounding are possible. (Note that random rounding, as in
Math::Round, is not implemented.)
-=over 2
+=over
=item 'trunc'
@@ -4388,7 +4406,7 @@ is 5 or greater, otherwise round down. E.g., 0.15 becomes 0.2 and
The handling of A & P in MBI/MBF (the old core code shipped with Perl
versions <= 5.7.2) is like this:
-=over 2
+=over
=item Precision
@@ -4400,14 +4418,15 @@ versions <= 5.7.2) is like this:
* fround($a) rounds to $a significant digits
* only fdiv() and fsqrt() take A as (optional) parameter
- + other operations simply create the same number (fneg etc), or more (fmul)
- of digits
- + rounding/truncating is only done when explicitly calling one of fround
- or ffround, and never for BigInt (not implemented)
+ + other operations simply create the same number (fneg etc), or
+ more (fmul) of digits
+ + rounding/truncating is only done when explicitly calling one
+ of fround or ffround, and never for BigInt (not implemented)
* fsqrt() simply hands its accuracy argument over to fdiv.
- * the documentation and the comment in the code indicate two different ways
- on how fdiv() determines the maximum number of digits it should calculate,
- and the actual code does yet another thing
+ * the documentation and the comment in the code indicate two
+ different ways on how fdiv() determines the maximum number
+ of digits it should calculate, and the actual code does yet
+ another thing
POD:
max($Math::BigFloat::div_scale,length(dividend)+length(divisor))
Comment:
@@ -4415,16 +4434,18 @@ versions <= 5.7.2) is like this:
Actual code:
scale = max(scale, length(dividend)-1,length(divisor)-1);
scale += length(divisor) - length(dividend);
- So for lx = 3, ly = 9, scale = 10, scale will actually be 16 (10+9-3).
- Actually, the 'difference' added to the scale is calculated from the
- number of "significant digits" in dividend and divisor, which is derived
- by looking at the length of the mantissa. Which is wrong, since it includes
- the + sign (oops) and actually gets 2 for '+100' and 4 for '+101'. Oops
- again. Thus 124/3 with div_scale=1 will get you '41.3' based on the strange
- assumption that 124 has 3 significant digits, while 120/7 will get you
- '17', not '17.1' since 120 is thought to have 2 significant digits.
- The rounding after the division then uses the remainder and $y to determine
- whether it must round up or down.
+ So for lx = 3, ly = 9, scale = 10, scale will actually be 16 (10
+ So for lx = 3, ly = 9, scale = 10, scale will actually be 16
+ (10+9-3). Actually, the 'difference' added to the scale is cal-
+ culated from the number of "significant digits" in dividend and
+ divisor, which is derived by looking at the length of the man-
+ tissa. Which is wrong, since it includes the + sign (oops) and
+ actually gets 2 for '+100' and 4 for '+101'. Oops again. Thus
+ 124/3 with div_scale=1 will get you '41.3' based on the strange
+ assumption that 124 has 3 significant digits, while 120/7 will
+ get you '17', not '17.1' since 120 is thought to have 2 signif-
+ icant digits. The rounding after the division then uses the
+ remainder and $y to determine whether it must round up or down.
? I have no idea which is the right way. That's why I used a slightly more
? simple scheme and tweaked the few failing testcases to match it.
@@ -4432,7 +4453,7 @@ versions <= 5.7.2) is like this:
This is how it works now:
-=over 2
+=over
=item Setting/Accessing
@@ -4614,7 +4635,7 @@ This is how it works now:
While BigInt has extensive handling of inf and NaN, certain quirks remain.
-=over 2
+=over
=item oct()/hex()
@@ -4747,16 +4768,16 @@ change.
use Math::BigInt;
- sub bint { Math::BigInt->new(shift); }
+ sub bigint { Math::BigInt->new(shift); }
$x = Math::BigInt->bstr("1234") # string "1234"
$x = "$x"; # same as bstr()
$x = Math::BigInt->bneg("1234"); # BigInt "-1234"
$x = Math::BigInt->babs("-12345"); # BigInt "12345"
$x = Math::BigInt->bnorm("-0.00"); # BigInt "0"
- $x = bint(1) + bint(2); # BigInt "3"
- $x = bint(1) + "2"; # ditto (auto-BigIntify of "2")
- $x = bint(1); # BigInt "1"
+ $x = bigint(1) + bigint(2); # BigInt "3"
+ $x = bigint(1) + "2"; # ditto (auto-BigIntify of "2")
+ $x = bigint(1); # BigInt "1"
$x = $x + 5 / 2; # BigInt "3"
$x = $x ** 3; # BigInt "27"
$x *= 2; # BigInt "54"
@@ -4881,7 +4902,7 @@ For more benchmark results see L<http://bloodgate.com/perl/benchmarks.html>.
The basic design of Math::BigInt allows simple subclasses with very little
work, as long as a few simple rules are followed:
-=over 2
+=over
=item *
@@ -4950,7 +4971,7 @@ the class Foo::Bar. Usually this is used in conjunction with Math::BigFloat:
use Math::BigInt upgrade => 'Math::BigFloat';
-As a shortcut, you can use the module C<bignum>:
+As a shortcut, you can use the module L<bignum>:
use bignum;
@@ -4968,7 +4989,7 @@ Beware: This feature is not fully implemented yet.
The following methods upgrade themselves unconditionally; that is if upgrade
is in effect, they will always hand up their work:
-=over 2
+=over
=item bsqrt()
@@ -4998,7 +5019,7 @@ C<Math::BigInt> exports nothing by default, but can export the following methods
Some things might not work as you expect them. Below is documented what is
known to be troublesome:
-=over 1
+=over
=item bstr(), bsstr() and 'cmp'
@@ -5052,7 +5073,7 @@ comparing them as strings:
$y = Math::BigInt->new($y);
ok ($x,$y); # okay
-Alternatively, simple use C<< <=> >> for comparisons, this will get it
+Alternatively, simply use C<< <=> >> for comparisons, this will get it
always right. There is not yet a way to get a number automatically represented
as a string that matches exactly the way Perl represents it.
@@ -5087,7 +5108,7 @@ when you access an array:
$z = $array[$x]; # does work automatically
-=item length
+=item length()
The following will probably not do what you expect:
@@ -5099,7 +5120,7 @@ since print calls C<length()> in list context. Use something like:
print scalar $c->length(),"\n"; # prints 3
-=item bdiv
+=item bdiv()
The following will probably not do what you expect:
@@ -5110,9 +5131,10 @@ context. Also, C<bdiv()> will modify $c, so be careful. You probably want
to use
print $c / 10000,"\n";
- print scalar $c->bdiv(10000),"\n"; # or if you want to modify $c
-instead.
+or, if you want to modify $c instead,
+
+ print scalar $c->bdiv(10000),"\n";
The quotient is always the greatest integer less than or equal to the
real-valued quotient of the two operands, and the remainder (when it is
diff --git a/Master/tlpkg/tlperl/lib/Math/BigInt/Calc.pm b/Master/tlpkg/tlperl/lib/Math/BigInt/Calc.pm
index 69092370533..3d886910005 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigInt/Calc.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigInt/Calc.pm
@@ -2,9 +2,9 @@ package Math::BigInt::Calc;
use 5.006002;
use strict;
-# use warnings; # dont use warnings for older Perls
+# use warnings; # do not use warnings for older Perls
-our $VERSION = '1.997';
+our $VERSION = '1.998';
# Package to store unsigned big integers in decimal and do math with them
@@ -23,7 +23,7 @@ our $VERSION = '1.997';
# Beware of things like:
# $i = $i * $y + $car; $car = int($i / $BASE); $i = $i % $BASE;
-# This works on x86, but fails on ARM (SA1100, iPAQ) due to whoknows what
+# This works on x86, but fails on ARM (SA1100, iPAQ) due to who knows what
# reasons. So, use this instead (slower, but correct):
# $i = $i * $y + $car; $car = int($i / $BASE); $i -= $BASE * $car;
@@ -1566,7 +1566,7 @@ sub _nok {
else {
- # Make a copy of the original n, since we'll be modifing n in-place.
+ # Make a copy of the original n, since we'll be modifying n in-place.
my $n_orig = _copy($c, $n);
diff --git a/Master/tlpkg/tlperl/lib/Math/BigInt/CalcEmu.pm b/Master/tlpkg/tlperl/lib/Math/BigInt/CalcEmu.pm
index c82e1539865..bcf74a8ab8f 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigInt/CalcEmu.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigInt/CalcEmu.pm
@@ -2,10 +2,10 @@ package Math::BigInt::CalcEmu;
use 5.006002;
use strict;
-# use warnings; # dont use warnings for older Perls
+# use warnings; # do not use warnings for older Perls
use vars qw/$VERSION/;
-$VERSION = '1.998';
+$VERSION = '1.9991';
package Math::BigInt;
@@ -305,11 +305,15 @@ using a call to the native lib.
=head1 METHODS
-=head2 __emu_bxor
+=over
-=head2 __emu_band
+=item __emu_bxor
-=head2 __emu_bior
+=item __emu_band
+
+=item __emu_bior
+
+=back
=head1 LICENSE
diff --git a/Master/tlpkg/tlperl/lib/Math/BigInt/FastCalc.pm b/Master/tlpkg/tlperl/lib/Math/BigInt/FastCalc.pm
index 81f29a16e4f..9bf5a60839e 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigInt/FastCalc.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigInt/FastCalc.pm
@@ -8,7 +8,7 @@ use Math::BigInt::Calc 1.997;
use vars '$VERSION';
-$VERSION = '0.30';
+$VERSION = '0.31';
##############################################################################
# global constants, flags and accessory
diff --git a/Master/tlpkg/tlperl/lib/Math/BigInt/Trace.pm b/Master/tlpkg/tlperl/lib/Math/BigInt/Trace.pm
index 4c51e5773da..79fc0970e47 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigInt/Trace.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigInt/Trace.pm
@@ -12,7 +12,7 @@ use vars qw($VERSION @ISA $PACKAGE @EXPORT_OK
@ISA = qw(Exporter Math::BigInt);
-$VERSION = '0.32';
+$VERSION = '0.36';
use overload; # inherit overload from BigInt
diff --git a/Master/tlpkg/tlperl/lib/Math/BigRat.pm b/Master/tlpkg/tlperl/lib/Math/BigRat.pm
index a70a42905a9..15b2ed08fe8 100644
--- a/Master/tlpkg/tlperl/lib/Math/BigRat.pm
+++ b/Master/tlpkg/tlperl/lib/Math/BigRat.pm
@@ -24,7 +24,7 @@ use vars qw($VERSION @ISA $upgrade $downgrade
@ISA = qw(Math::BigFloat);
-$VERSION = '0.2604';
+$VERSION = '0.2606';
$VERSION = eval $VERSION;
# inherit overload from Math::BigFloat, but disable the bitwise ops that don't
@@ -258,7 +258,7 @@ sub new
if ($n->{sign} =~ /^[+-]$/ && $d->{sign} =~ /^[+-]$/)
{
- # both parts are ok as integers (wierd things like ' 1e0'
+ # both parts are ok as integers (weird things like ' 1e0'
$self->{_n} = $MBI->_copy($n->{value});
$self->{_d} = $MBI->_copy($d->{value});
$self->{sign} = $n->{sign};
@@ -446,7 +446,7 @@ sub bneg
return $x if $x->modify('bneg');
- # for +0 dont negate (to have always normalized +0). Does nothing for 'NaN'
+ # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN'
$x->{sign} =~ tr/+-/-+/ unless ($x->{sign} eq '+' && $MBI->_is_zero($x->{_n}));
$x;
}
@@ -1271,7 +1271,7 @@ sub bsqrt
$x->{_n} = _float_from_part( $x->{_n} )->bsqrt();
$x->{_d} = _float_from_part( $x->{_d} )->bsqrt();
- # XXX TODO: we probably can optimze this:
+ # XXX TODO: we probably can optimize this:
# if sqrt(D) was not integer
if ($x->{_d}->{_es} ne '+')
@@ -1925,7 +1925,7 @@ Euler's number.
This method was added in v0.20 of Math::BigRat (May 2007).
-See also L</blog()>.
+See also C<blog()>.
=head2 bnok()
diff --git a/Master/tlpkg/tlperl/lib/Math/Int64.pm b/Master/tlpkg/tlperl/lib/Math/Int64.pm
index 21be450ebfb..0dad403e899 100755
--- a/Master/tlpkg/tlperl/lib/Math/Int64.pm
+++ b/Master/tlpkg/tlperl/lib/Math/Int64.pm
@@ -4,10 +4,9 @@ use strict;
use warnings;
BEGIN {
- our $VERSION = '0.30';
-
- require XSLoader;
- XSLoader::load('Math::Int64', $VERSION);
+our $VERSION = '0.52';
+require XSLoader;
+XSLoader::load('Math::Int64', $VERSION);
}
use constant MAX_INT64 => string_to_int64 ( '0x7fff_ffff_ffff_ffff');
@@ -100,7 +99,8 @@ use overload ( '+' => \&_add,
'=' => \&_clone,
fallback => 1 );
-package Math::UInt64;
+package # hide from PAUSE since it also has its own .pm file
+ Math::UInt64;
use overload ( '+' => \&_add,
'+=' => \&_add,
'-' => \&_sub,
@@ -138,8 +138,12 @@ use overload ( '+' => \&_add,
1;
+# ABSTRACT: Manipulate 64 bits integers in Perl
+
__END__
+=encoding UTF-8
+
=head1 NAME
Math::Int64 - Manipulate 64 bits integers in Perl
@@ -262,7 +266,7 @@ rule:
That way, positive and negative integers are interleaved as 0, -1, 1,
2, -2, .... The format is similar to that used by Google protocol
-buffers to encode signed varints but with the most significant groups
+buffers to encode signed variants but with the most significant groups
first (protocol buffers uses the least significant groups first
variant).
@@ -280,7 +284,7 @@ There must not be any extra bytes on the string after the encoded number.
Given a string with a BER encoded number at the beginning, this
function returns the number of bytes it uses.
-The rigth way to shift a BER encoded number from the beginning of some
+The right way to shift a BER encoded number from the beginning of some
string is as follows:
$i64 = BER_to_int64(substr($str, 0, BER_length($str), ''));
@@ -328,6 +332,10 @@ Encodes the given unsigned integer in BER format (see L<perlfunc/pack>).
Decodes from the given string an unsigned number in BER format.
+=item uint64_rand
+
+Generates a 64 bit random unsigned number using ISAAC-64 algorithm.
+
=back
=head2 Die on overflow
@@ -362,7 +370,7 @@ C<die_on_overflow> pragma is global and can not be deactivated.
If the lexical pragma C<Math::Int64::native_if_available> is used in
your program and the version of perl in use has native support for
-64bit intgers, the functions imported from the module that create
+64bit integers, the functions imported from the module that create
64bit integers (i.e. C<uint64>, C<int64>, C<string_to_int64>,
C<native_to_int64>, etc.) will return regular perl scalars.
@@ -380,9 +388,10 @@ This feature is not enabled by default because the semantics for perl
scalars and for 64 bit integers as implemented in this module are not
identical.
-Perl is prone to coerze integers into floats while this module keeps
+Perl is prone to coerce integers into floats while this module keeps
then always as 64bit integers. Specifically, the division operation
-and overflows are the most problematic cases.
+and overflows are the most problematic cases. Also, when using native
+integers, the signed/unsigned division blurs.
Besides that, in most situations it is safe to use the native fallback.
@@ -452,22 +461,22 @@ For instance:
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
-
+
/* #define MATH_INT64_NATIVE_IF_AVAILABLE */
#include "math_int64.h"
-
+
MODULE = Foo64 PACKAGE = Foo64
BOOT:
PERL_MATH_INT64_LOAD_OR_CROAK;
-
+
int64_t
some_int64()
CODE:
RETVAL = -42;
OUTPUT:
RETVAL
-
-
+
+
--- Makefile.PL -----
use ExtUtils::MakeMaker;
@@ -513,6 +522,14 @@ Returns true is the given SV contains a valid uint64_t value.
Returns a random 64 bits unsigned integer.
+=item SV sv_seti64(SV *sv, uint64_t i64)
+
+Sets the value of the perl scalar to the given int64_t value.
+
+=item SV sv_setu64(SV *sv, uint64_t i64)
+
+Sets the value of the perl scalar to the given uint64_t value.
+
=back
If you require any other function available through the C API don't
@@ -527,7 +544,7 @@ The C API feature is experimental.
This module requires int64 support from the C compiler.
In order to report bugs you can send me and email to the address that
-appears below or use the CPAN RT bugtracking system available at
+appears below or use the CPAN RT bug tracking system available at
L<http://rt.cpan.org>.
The source for the development version of the module is hosted at
@@ -549,9 +566,11 @@ L<Math::BigInt::GMP>.
=head1 COPYRIGHT AND LICENSE
-Copyright E<copy> 2007, 2009, 2011-2013 by Salvador FandiE<ntilde>o
+Copyright E<copy> 2007, 2009, 2011-2015 by Salvador FandiƱo
(sfandino@yahoo.com)
+Copyright E<copy> 2014-2015 by Dave Rolsky (autarch@urth.org)
+
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.
diff --git a/Master/tlpkg/tlperl/lib/Math/Int64/die_on_overflow.pm b/Master/tlpkg/tlperl/lib/Math/Int64/die_on_overflow.pm
index 9c5b10c084b..ce2c8f732c9 100755
--- a/Master/tlpkg/tlperl/lib/Math/Int64/die_on_overflow.pm
+++ b/Master/tlpkg/tlperl/lib/Math/Int64/die_on_overflow.pm
@@ -1,5 +1,8 @@
package Math::Int64::die_on_overflow;
+use strict;
+use warnings;
+
sub import {
require Math::Int64;
Math::Int64::_set_may_die_on_overflow(1);
@@ -13,8 +16,12 @@ sub unimport {
1;
+# ABSTRACT: catch overflows when using Math::Int64
+
__END__
+=encoding UTF-8
+
=head1 NAME
Math::Int64::die_on_overflow - catch overflows when using Math::Int64
@@ -32,13 +39,4 @@ Math::Int64::die_on_overflow - catch overflows when using Math::Int64
L<Math::Int64>.
-=head1 COPYRIGHT AND LICENSE
-
-Copyright E<copy> 2011 by Salvador FandiE<ntilde>o
-(sfandino@yahoo.com)
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself, either Perl version 5.8.8 or,
-at your option, any later version of Perl 5 you may have available.
-
=cut
diff --git a/Master/tlpkg/tlperl/lib/Math/Int64/native_if_available.pm b/Master/tlpkg/tlperl/lib/Math/Int64/native_if_available.pm
index 170475dafab..b52466005d7 100755
--- a/Master/tlpkg/tlperl/lib/Math/Int64/native_if_available.pm
+++ b/Master/tlpkg/tlperl/lib/Math/Int64/native_if_available.pm
@@ -1,14 +1,40 @@
package Math::Int64::native_if_available;
+use strict;
+use warnings;
+
sub import {
if (Math::Int64::_backend() eq 'IV' and $] >= 5.008) {
Math::Int64::_set_may_use_native(1);
- $^H{Math::Int64::native_if_available} = 1;
+ $^H{'Math::Int64::native_if_available'} = 1;
}
}
sub unimport {
- undef $^H{Math::Int64::native_if_available};
+ undef $^H{'Math::Int64::native_if_available'};
}
1;
+
+# ABSTRACT: Use the native Perl 64-bit integer implementation when available
+
+__END__
+
+=encoding UTF-8
+
+=head1 NAME
+
+Math::Int64::native_if_available - Use the native Perl 64-bit integer implementation when available
+
+=head1 SYNOPSIS
+
+ use Math::Int64 qw(uint64);
+ use Math::Int64::native_if_available;
+
+=head1 SEE ALSO
+
+L<Math::Int64>.
+
+=cut
+
+
diff --git a/Master/tlpkg/tlperl/lib/Math/UInt64.pm b/Master/tlpkg/tlperl/lib/Math/UInt64.pm
index 956cb4a2e61..6fc6d03ef25 100755
--- a/Master/tlpkg/tlperl/lib/Math/UInt64.pm
+++ b/Master/tlpkg/tlperl/lib/Math/UInt64.pm
@@ -1,14 +1,20 @@
package Math::UInt64;
-require Math::Int64;
-require Carp;
+use strict;
+use warnings;
+
+use Math::Int64;
sub import { goto &Math::Int64::import }
1;
+# ABSTRACT: Manipulate 64 bit unsigned integers from Perl
+
__END__
+=encoding UTF-8
+
=head1 NAME
Math::UInt64 - Manipulate 64 bit unsigned integers from Perl
@@ -23,13 +29,4 @@ demand.
L<Math::Int64>.
-=head1 COPYRIGHT AND LICENSE
-
-Copyright E<copy> 2007, 2009, 2011-2013 by Salvador FandiE<ntilde>o
-(sfandino@yahoo.com)
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself, either Perl version 5.8.8 or,
-at your option, any later version of Perl 5 you may have available.
-
=cut