NAME
Math::BigNum - Arbitrary size precision for integers, rationals and floating-point numbers.
VERSION
Version 0.18
SYNOPSIS
use 5.014;
use Math::BigNum qw(:constant);
# Big numbers
say ((100->fac + 1) / 2);
# => 466631077219720763408496194281333502453579841321908107 \
# 342964819476087999966149578044707319880782591431268489 \
# 60413611879125592605458432000000000000000000000000.5
# Small numbers
say sqrt(1 / 100->fac); # => 1.03513781117562647132049[...]e-79
# Rational numbers
my $x = 2/3;
say $x*3; # => 2
say 2/$x; # => 3
say $x->as_frac; # => "2/3"
# Floating-point numbers
say "equal" if (1.1 + 2.2 == 3.3); # => "equal"
DESCRIPTION
Math::BigNum provides a transparent interface to Math::GMPz, Math::GMPq and Math::MPFR, focusing on performance and easy-to-use. In most cases, it can be used as a drop-in replacement for the bignum and bigrat pragmas.
MOTIVATION
This module came into existence as a response to Dana Jacobsen's request for a transparent interface to Math::GMPz and Math::MPFR, which he talked about at the YAPC NA, in 2015.
See his great presentation at: https://www.youtube.com/watch?v=Dhl4_Chvm_g.
The main aim of this module is to provide a fast and correct alternative to Math::BigInt, Maht::BigFloat and Math::BigRat, as well as to bigint, bignum and bigrat pragmas.
HOW IT WORKS
Math::BigNum tries really hard to do the right thing and as efficiently as possible. For example, when computing pow(x, y)
, it first checks to see if x
and y
are integers, so it can optimize the operation to integer exponentiation, by calling the corresponding mpz function. When only y
is an integer, it does rational exponentiation based on the identity: (a/b)^n = a^n / b^n. Otherwise, it will fallback to floating-point exponentiation, using the corresponding mpfr function.
All numbers in Math::BigNum are stored as rational Math::GMPq objects. Each operation, outside the functions provided by Math::GMPq, is done by converting the internal objects to Math::GMPz or Math::MPFR objects and calling the corresponding functions, converting the results back to Math::GMPq objects, without loosing any precision in the process.
IMPORT / EXPORT
Math::BigNum does not export anything by default, but it recognizes the followings:
:constant # will make any number a Math::BigNum object
# it will also export the "Inf" and "NaN" constants,
# which represent +Infinity and NaN special values
:all # export everything that is exportable
PREC n # set the global precision to the value of `n`
Numerical constants:
e # "e" constant (2.7182...)
pi # "pi" constant (3.1415...)
tau # "tau" constant (which is: 2*pi)
phi # Golden ratio constant (1.618...)
G # Catalan's constant (0.91596...)
Y # Euler-Mascheroni constant (0.57721...)
Inf # +Infinity constant
NaN # Not-a-Number constant
Special functions:
factorial(n) # product of first n integers: n!
primorial(n) # product of primes <= n
binomial(n,k) # binomial coefficient
fibonacci(n) # nth-Fibonacci number
lucas(n) # nth-Lucas number
ipow(a,k) # integer exponentiation: a^k
NOTE: this functions are designed and optimized for native Perl integers as input.
The syntax for importing something, is:
use Math::BigNum qw(:constant pi factorial);
say cos(2*pi); # => 1
say factorial(5); # => 120
NOTE: :constant
is lexical to the current scope only.
The syntax for disabling the :constant
behavior in the current scope, is:
no Math::BigNum; # :constant will be disabled in the current scope
PRECISION
The default precision for floating-point numbers is 200 bits, which is equivalent with about 50 digits of precision in base 10.
The precision can be changed by modifying the $Math::BigNum::PREC
variable, such as:
local $Math::BigNum::PREC = 1024;
or by specifying the precision at import (this sets the precision globally):
use Math::BigNum PREC => 1024;
However, an important thing to take into account, unlike the Math::MPFR objects, Math::BigNum objects do not have a fixed precision stored inside. Rather, they can grow or shrink dynamically, regardless of the global precision.
The global precision controls only the precision of the floating-point functions and the stringification of floating-point numbers.
For example, if we change the precision to 3 decimal digits (where 4
is the conversion factor), we get the following results:
local $Math::BigNum::PREC = 3*4;
say sqrt(2); # => 1.414
say 98**7; # => 86812553324672
say 1 / 98**7 # => 1.15e-14
As shown above, integers do not obey the global precision, because they can grow or shrink dynamically, without a specific limit. This is true for rational numbers as well.
A rational number never losses precision in rational operations, therefore if we say:
my $x = 1 / 3;
say $x * 3; # => 1
say 1 / $x; # => 3
say 3 / $x; # => 9
...the results are 100% exact.
NOTATIONS
Methods that begin with a b followed by the actual name (e.g.: bsqrt
), are mutable methods that change the self object in-place, while their counter-parts (e.g.: sqrt
) do not. Instead, they will create and return a new object.
In addition, Math::BigNum features another kind of methods that begin with an i followed by the actual name (e.g.: isqrt
). This methods do integer operations, by first truncating their arguments to integers, whenever needed.
Lastly, Math::BigNum implements another kind of methods that begin with an f followed by the actual name (e.g.: fdiv
). This methods do floating-point operations and are usually faster than their rational counterparts when invoked on very large or very small real-numbers.
The returned types are noted as follows:
BigNum # a "Math::BigNum" object
Inf # a "Math::BigNum::Inf" object
Nan # a "Math::BigNum::Nan" object
Scalar # a Perl number or string
Bool # true or false (actually: 1 or 0)
When two or more types are separated with pipe characters (|), it means that the corresponding function can return any of the specified types.
PERFORMANCE
The performance varies greatly, but, in most cases, Math::BigNum is between 2x up to 10x faster than Math::BigFloat with the GMP backend, and about 100x faster than Math::BigFloat without the GMP backend (to be modest).
Math::BigNum is fast because of the following facts:
minimal overhead in object creation.
minimal Perl code is executed per operation.
the GMP and MPFR libraries are extremely efficient.
To achieve the best performance, try to follow this rules:
use the b* methods whenever you can.
use the i* methods wherever applicable.
use the f* methods when accuracy is not important.
pass Perl numbers as arguments to methods, if you can.
avoid the stringification of non-integer Math::BigNum objects.
don't use copy followed by a b* method! Just leave out the b.
INITIALIZATION / CONSTANTS
This section includes methods for creating new Math::BigNum objects and some useful mathematical constants.
new
BigNum->new(Scalar) # => BigNum
BigNum->new(Scalar, Scalar) # => BigNum
Returns a new BigNum object with the value specified in the first argument, which can be a Perl numerical value, a string representing a number in a rational form, such as "1/2"
, a string holding a floating-point number, such as "0.5"
, or a string holding an integer, such as "255"
.
The second argument specifies the base of the number, which can range from 2 to 36 inclusive and defaults to 10.
For setting an hexadecimal number, we can say:
my $x = Math::BigNum->new("deadbeef", 16);
NOTE: no prefix, such as "0x"
or "0b"
, is allowed as part of the number.
new_int
BigNum->new_int(Scalar) # => BigNum
A faster version of the method new()
for setting a signed native integer.
Example:
my $x = Math::BigNum->new_int(-42);
new_uint
BigNum->new_uint(Scalar) # => BigNum
A faster version of the method new()
for setting an unsigned native integer.
Example:
my $x = Math::BigNum->new_uint(42);
nan
BigNum->nan # => Nan
Returns a new Nan object.
inf
BigNum->inf # => Inf
Returns a new Inf object to represent positive Infinity.
ninf
BigNum->ninf # => -Inf
Returns an Inf object to represent negative Infinity.
one
BigNum->one # => BigNum
Returns a BigNum object containing the value 1
.
zero
BigNum->zero # => BigNum
Returns a BigNum object containing the value 0
.
mone
BigNum->mone # => BigNum
Returns a BigNum object containing the value -1
.
bzero
$x->bzero # => BigNum
Changes x
in-place to hold the value 0.
bone
$x->bone # => BigNum
Changes x
in-place to hold the value +1.
bmone
$x->bmone # => BigNum
Changes x
in-place to hold the value -1.
binf
$x->binf # => Inf
Changes x
in-place to positive Infinity.
bninf
$x->bninf # => -Inf
Changes x
in-place to negative Infinity.
bnan
$x->bnan # => Nan
Changes x
in-place to the special Not-a-Number value.
pi
BigNum->pi # => BigNum
Returns the number PI, which is 3.1415...
.
tau
BigNum->tau # => BigNum
Returns the number TAU, which is 2*PI
.
ln2
BigNum->ln2 # => BigNum
Returns the natural logarithm of 2
.
Y
BigNum->Y # => BigNum
Returns the Euler-Mascheroni constant, which is 0.57721...
.
G
BigNum->G # => BigNum
Returns the value of Catalan's constant, also known as Beta(2) or G, and starts as: 0.91596...
.
e
BigNum->e # => BigNum
Returns the e mathematical constant, which is 2.718...
.
phi
BigNum->phi # => BigNum
Returns the value of the golden ratio, which is 1.61803...
.
RATIONAL OPERATIONS
All operations in this section are done rationally, which means that the returned results are 100% exact (unless otherwise stated in some special cases).
add
$x->add(BigNum) # => BigNum
$x->add(Scalar) # => BigNum
BigNum + BigNum # => BigNum
BigNum + Scalar # => BigNum
Scalar + BigNum # => BigNum
Adds y
to x
and returns the result.
badd
$x->badd(BigNum) # => BigNum
$x->badd(Scalar) # => BigNum
BigNum += BigNum # => BigNum
BigNum += Scalar # => BigNum
Adds y
to x
, changing x
in-place.
sub
$x->sub(BigNum) # => BigNum
$x->sub(Scalar) # => BigNum
BigNum - BigNum # => BigNum
BigNum - Scalar # => BigNum
Scalar - BigNum # => BigNum
Subtracts y
from x
and returns the result.
bsub
$x->bsub(BigNum) # => BigNum
$x->bsub(Scalar) # => BigNum
BigNum -= BigNum # => BigNum
BigNum -= Scalar # => BigNum
Subtracts y
from x
by changing x
in-place.
mul
$x->mul(BigNum) # => BigNum
$x->mul(Scalar) # => BigNum
BigNum * BigNum # => BigNum
BigNum * Scalar # => BigNum
Scalar * BigNum # => BigNum
Multiplies x
by y
and returns the result.
bmul
$x->bmul(BigNum) # => BigNum
$x->bmul(Scalar) # => BigNum
BigNum *= BigNum # => BigNum
BigNum *= Scalar # => BigNum
Multiply x
by y
, changing x
in-place.
div
$x->div(BigNum) # => BigNum | Inf | Nan
$x->div(Scalar) # => BigNum | Inf | Nan
BigNum / BigNum # => BigNum | Inf | Nan
BigNum / Scalar # => BigNum | Inf | Nan
Scalar / BigNum # => BigNum | Inf | Nan
Divides x
by y
and returns the result. Returns Nan when x
and y
are 0, Inf when y
is 0 and x
is positive, -Inf when y
is zero and x
is negative.
bdiv
$x->bdiv(BigNum) # => BigNum | Nan | Inf
$x->bdiv(Scalar) # => BigNum | Nan | Inf
BigNum /= BigNum # => BigNum | Nan | Inf
BigNum /= Scalar # => BigNum | Nan | Inf
Divide x
by y
, changing x
in-place. The return values are the same as for div()
.
mod
$x->mod(BigNum) # => BigNum | Nan
$x->mod(Scalar) # => BigNum | Nan
BigNum % BigNum # => BigNum | Nan
BigNum % Scalar # => BigNum | Nan
Scalar % BigNum # => BigNum | Nan
Remainder of x
when is divided by y
. Returns Nan when y
is zero.
When x
and y
are both integers, the returned result is exact. Otherwise, the result is a floating-point approximation.
bmod
$x->bmod(BigNum) # => BigNum | Nan
$x->bmod(Scalar) # => BigNum | Nan
BigNum %= BigNum # => BigNum | Nan
BigNum %= Scalar # => BigNum | Nan
Sets x
to the remainder of x
when is divided by y
. Sets x
to Nan when y
is zero.
pow
$x->pow(BigNum) # => BigNum | Nan
$x->pow(Scalar) # => BigNum | Nan
BigNum ** BigNum # => BigNum | Nan
BigNum ** Scalar # => BigNum | Nan
Scalar ** BigNum # => BigNum | Nan
Raises x
to power y
. Returns Nan when x
is negative and y
is not an integer.
When both x
and y
are integers, it does integer exponentiation and returns the exact result.
When only y
is an integer, it does rational exponentiation based on the identity: (a/b)^n = a^n / b^n
, which computes the exact result.
When x
and y
are rationals, it does floating-point exponentiation, which is, in most cases, equivalent with: x^y = exp(log(x) * y)
, in which the returned result may not be exact.
bpow
$x->bpow(BigNum) # => BigNum | Nan
$x->bpow(Scalar) # => BigNum | Nan
BigNum **= BigNum # => BigNum | Nan
BigNum **= Scalar # => BigNum | Nan
Scalar **= BigNum # => BigNum | Nan
Raises x
to power y
, changing x
in-place.
inv
$x->inv # => BigNum | Inf
Inverse value of x
. Return Inf when x
is zero. (1/x
)
binv
$x->binv # => BigNum | Inf
Set x
to its inverse value. (1/x
)
sqr
$x->sqr # => BigNum
Raise x
to the power of 2 and return the result. (x*x
)
bsqr
$x->bsqr # => BigNum
Set x
to its multiplicative double. (x*x
)
bernfrac
$n->bernfrac # => BigNum | Nan
Returns the nth-Bernoulli number B_n
as an exact fraction, computed with an improved version of Seidel's algorithm, starting with bernfrac(0) = 1
.
For n >= 50, a more efficient algorithm is used, based on Zeta(n).
For negative values of n
, Nan is returned.
harmfrac
$n->harmfrac # => BigNum | Nan
Returns the nth-Harmonic number H_n
. The harmonic numbers are the sum of reciprocals of the first n
natural numbers: 1 + 1/2 + 1/3 + ... + 1/n
.
For values greater than 7000, binary splitting (Fredrik Johansson's elegant formulation) is used.
FLOATING-POINT OPERATIONS
All the operations in this section are done with floating-point approximations, which are, in the end, converted to fraction-approximations. In some cases, the results are 100% exact, but this is not guaranteed.
fadd
$x->fadd(BigNum) # => BigNum
$x->fadd(Scalar) # => BigNum
Floating-point addition of x
and y
.
bfadd
$x->bfadd(BigNum) # => BigNum
$x->bfadd(Scalar) # => BigNum
Floating-point addition of x
and y
, changing x
in-place.
fsub
$x->fsub(BigNum) # => BigNum
$x->fsub(Scalar) # => BigNum
Floating-point subtraction of x
and y
.
bfsub
$x->bfsub(BigNum) # => BigNum
$x->bfsub(Scalar) # => BigNum
Floating-point subtraction of x
and y
, changing x
in-place.
fmul
$x->fmul(BigNum) # => BigNum
$x->fmul(Scalar) # => BigNum
Floating-point multiplication of x
by y
.
bfmul
$x->bfmul(BigNum) # => BigNum
$x->bfmul(Scalar) # => BigNum
Floating-point multiplication of x
by y
, changing x
in-place.
fdiv
$x->fdiv(BigNum) # => BigNum | Nan | Inf
$x->fdiv(Scalar) # => BigNum | Nan | Inf
Floating-point division of x
by y
.
bfdiv
$x->bfdiv(BigNum) # => BigNum | Nan | Inf
$x->bfdiv(Scalar) # => BigNum | Nan | Inf
Floating-point division of x
by y
, changing x
in-place.
fpow
$x->fpow(BigNum) # => BigNum | Inf | Nan
$x->fpow(Scalar) # => BigNum | Inf | Nan
Raises x
to power y
. Returns Nan when x
is negative and y
is not an integer.
bfpow
$x->bfpow(BigNum) # => BigNum | Inf | Nan
$x->bfpow(Scalar) # => BigNum | Inf | Nan
Raises x
to power y
, changing x
in-place. Promotes x
to Nan when x
is negative and y
is not an integer.
fmod
$x->fmod(BigNum) # => BigNum | Nan
$x->fmod(Scalar) # => BigNum | Nan
The remainder of x
when is divided by y
. Nan is returned when y
is zero.
bfmod
$x->bfmod(BigNum) # => BigNum | Nan
$x->bfmod(Scalar) # => BigNum | Nan
The remainder of x
when is divided by y
, changing x
in-place. Promotes x
to Nan when y
is zero.
sqrt
$x->sqrt # => BigNum | Nan
sqrt($x) # => BigNum | Nan
Square root of x
. Returns Nan when x
is negative.
bsqrt
$x->bsqrt # => BigNum | Nan
Square root of x
, changing x
in-place. Promotes x
to Nan when x
is negative.
cbrt
$x->cbrt # => BigNum | Nan
Cube root of x
. Returns Nan when x
is negative.
root
$x->root(BigNum) # => BigNum | Nan
$x->root(Scalar) # => BigNum | Nan
Nth root of x
. Returns Nan when x
is negative.
broot
$x->broot(BigNum) # => BigNum | Nan
$x->broot(Scalar) # => BigNum(1)
Nth root of x
, changing x
in-place. Promotes x
to Nan when x
is negative.
ln
$x->ln # => BigNum | Nan
Logarithm of x
in base e. Returns Nan when x
is negative.
bln
$x->bln # => BigNum | Nan
Logarithm of x
in base e, changing the x
in-place. Promotes x
to Nan when x
is negative.
log
$x->log # => BigNum | Nan
$x->log(BigNum) # => BigNum | Nan
$x->log(Scalar) # => BigNum | Nan
log(BigNum) # => BigNum | Nan
Logarithm of x
in base y
. When y
is not specified, it defaults to base e. Returns Nan when x
is negative and -Inf when x
is zero.
blog
$x->blog # => BigNum | Nan
$x->blog(BigNum) # => BigNum | Nan
$x->log(Scalar) # => BigNum | Nan
Logarithm of x
in base y
, changing the x
in-place. When y
is not specified, it defaults to base e.
log2
$x->log2 # => BigNum | Nan
Logarithm of x
in base 2. Returns Nan when x
is negative.
log10
$x->log10 # => BigNum | Nan
Logarithm of x
in base 10. Returns Nan when x
is negative.
lgrt
$x->lgrt # => BigNum | Nan
Logarithmic-root of x
, which is the largest solution to a^a = b
, where b
is known. It is defined in real numbers for values of x greater than or equal to 0.7
.
Example:
100->lgrt # solves for x in `x^x = 100` and returns: `3.59728...`
lambert_w
$x->lambert_w # => BigNum | Nan
The Lambert-W function, defined in real numbers. The value of x
should not be less than -1/e
.
Example:
100->log->lambert_w->exp # solves for x in `x^x = 100` and returns: `3.59728...`
exp
$x->exp # => BigNum
Exponential of x
in base e. (e^x
)
bexp
$x->bexp # => BigNum
Exponential of x
in base e, changing x
in-place.
exp2
$x->exp2 # => BigNum
Exponential of x
in base 2. (2^x
)
exp10
$x->exp10 # => BigNum
Exponential of x
in base 10. (10^x
)
* Trigonometry
sin
$x->sin # => BigNum
Returns the sine of x
.
asin
$x->asin # => BigNum | Nan
Returns the inverse sine of x
. Returns Nan for x < -1 or x > 1.
sinh
$x->sinh # => BigNum
Returns the hyperbolic sine of x
.
asinh
$x->asinh # => BigNum
Returns the inverse hyperbolic sine of x
.
cos
$x->cos # => BigNum
Returns the cosine of x
.
acos
$x->acos # => BigNum | Nan
Returns the inverse cosine of x
. Returns Nan for x < -1 or x > 1.
cosh
$x->cosh # => BigNum
Returns the hyperbolic cosine of x
.
acosh
$x->acosh # => BigNum | Nan
Returns the inverse hyperbolic cosine of x
. Returns Nan for x < 1.
tan
$x->tan # => BigNum
Returns the tangent of x
.
atan
$x->atan # => BigNum
Returns the inverse tangent of x
.
tanh
$x->tanh # => BigNum
Returns the hyperbolic tangent of x
.
atanh
$x->atanh # => BigNum | Nan
Returns the inverse hyperbolic tangent of x
. Returns Nan for x <= -1 or x >= 1.
sec
$x->sec # => BigNum
Returns the secant of x
.
asec
$x->asec # => BigNum | Nan
Returns the inverse secant of x
. Returns Nan for x > -1 and x < 1.
Defined as:
asec(x) = acos(1/x)
sech
$x->sech # => BigNum
Returns the hyperbolic secant of x
.
asech
$x->asech # => BigNum | Nan
Returns the inverse hyperbolic secant of x
. Returns a Nan for x < 0 or x > 1.
Defined as:
asech(x) = acosh(1/x)
csc
$x->csc # => BigNum
Returns the cosecant of x
.
acsc
$x->acsc # => BigNum | Nan
Returns the inverse cosecant of x
. Returns Nan for x > -1 and x < 1.
Defined as:
acsc(x) = asin(1/x)
csch
$x->csch # => BigNum
Returns the hyperbolic cosecant of x
.
acsch
$x->acsch # => BigNum
Returns the inverse hyperbolic cosecant of x
.
Defined as:
acsch(x) = asinh(1/x)
cot
$x->cot # => BigNum
Returns the cotangent of x
.
acot
$x->acot # => BigNum
Returns the inverse cotangent of x
.
Defined as:
acot(x) = atan(1/x)
coth
$x->coth # => BigNum
Returns the hyperbolic cotangent of x
.
acoth
$x->acoth # => BigNum
Returns the inverse hyperbolic cotangent of x
.
Defined as:
acoth(x) = atanh(1/x)
atan2
$x->atan2(BigNum) # => BigNum
$x->atan2(Scalar) # => BigNum
atan2(BigNum, BigNum) # => BigNum
atan2(BigNum, Scalar) # => BigNum
atan2(Scalar, BigNum) # => BigNum
Arctangent of x
and y
. When y
is -Inf returns PI when x >= 0, or -PI
when x < 0.
* Special methods
agm
$x->agm(BigNum) # => BigNum
$x->agm(Scalar) # => BigNum
Arithmetic-geometric mean of x
and y
.
hypot
$x->hypot(BigNum) # => BigNum
$x->hypot(Scalar) # => BigNum
The value of the hypotenuse for catheti x
and y
. (sqrt(x^2 + y^2)
)
gamma
$x->gamma # => BigNum | Inf | Nan
The Gamma function on x
. Returns Inf when x
is zero, and Nan when x
is negative.
lngamma
$x->lngamma # => BigNum | Inf
The natural logarithm of the Gamma function on x
. Returns Inf when x
is negative or equal to zero.
lgamma
$x->lgamma # => BigNum | Inf
The logarithm of the absolute value of the Gamma function. Returns Inf when x
is negative or equal to zero.
digamma
$x->digamma # => BigNum | Inf | Nan
The Digamma function (sometimes also called Psi). Returns Nan when x
is negative, and -Inf when x
is 0.
beta
$x->beta(BigNum) # => BigNum | Inf | Nan
The beta function (also called the Euler integral of the first kind).
Defined as:
beta(x,y) = gamma(x)*gamma(y) / gamma(x+y)
for x > 0 and y > 0.
zeta
$x->zeta # => BigNum | Inf
The Riemann zeta function at x
. Returns Inf when x
is 1.
eta
$x->eta # => BigNum
The Dirichlet eta function at x
.
Defined as:
eta(1) = ln(2)
eta(x) = (1 - 2**(1-x)) * zeta(x)
bessel_j
$x->bessel_j(BigNum) # => BigNum
$x->bessel_j(Scalar) # => BigNum
The first order Bessel function, J_n(x)
, where n
is a signed integer.
Example:
$x->bessel_j($n) # represents J_n(x)
bessel_y
$x->bessel_y(BigNum) # => BigNum | Inf | Nan
$x->bessel_y(Scalar) # => BigNum | Inf | Nan
The second order Bessel function, Y_n(x)
, where n
is a signed integer. Returns Nan for negative values of x
.
Example:
$x->bessel_y($n) # represents Y_n(x)
bernreal
$n->bernreal # => BigNum | Nan
Returns the nth-Bernoulli number, as a floating-point approximation, with bernreal(0) = 1
.
Returns Nan for negative values of n
.
harmreal
$n->harmreal # => BigNum | Nan
Returns the nth-Harmonic number, as a floating-point approximation, for any real value of n
>= 0.
Defined as:
harmreal(n) = digamma(n+1) + gamma
where gamma
is the Euler-Mascheroni constant.
erf
$x->erf # => BigNum
The error function on x
.
erfc
$x->erfc # => BigNum
Complementary error function on x
.
eint
$x->eint # => BigNum | Inf | Nan
Exponential integral of x
. Returns -Inf when x
is zero, and Nan when x
is negative.
li
$x->li # => BigNum | Inf | Nan
The logarithmic integral of x
, defined as: Ei(ln(x))
. Returns -Inf when x
is 1, and Nan when x
is less than or equal to 0.
li2
$x->li2 # => BigNum
The dilogarithm function, defined as the integral of -log(1-t)/t
from 0 to x
.
INTEGER OPERATIONS
All the operations in this section are done with integers.
iadd
$x->iadd(BigNum) # => BigNum
$x->iadd(Scalar) # => BigNum
Integer addition of y
to x
. Both values are truncated to integers before addition.
biadd
$x->biadd(BigNum) # => BigNum
$x->biadd(Scalar) # => BigNum
Integer addition of y
from x
, changing x
in-place. Both values are truncated to integers before addition.
isub
$x->isub(BigNum) # => BigNum
$x->isub(Scalar) # => BigNum
Integer subtraction of y
from x
. Both values are truncated to integers before subtraction.
bisub
$x->bisub(BigNum) # => BigNum
$x->bisub(Scalar) # => BigNum
Integer subtraction of y
from x, changing x
in-place. Both values are truncated to integers before subtraction.
imul
$x->imul(BigNum) # => BigNum
$x->imul(Scalar) # => BigNum
Integer multiplication of x
by y
. Both values are truncated to integers before multiplication.
bimul
$x->bimul(BigNum) # => BigNum
$x->bimul(Scalar) # => BigNum
Integer multiplication of x
by y
, changing x
in-place. Both values are truncated to integers before multiplication.
idiv
$x->idiv(BigNum) # => BigNum | Nan | Inf
$x->idiv(Scalar) # => BigNum | Nan | Inf
Integer division of x
by y
.
bidiv
$x->bidiv(BigNum) # => BigNum | Nan | Inf
$x->bidiv(Scalar) # => BigNum | Nan | Inf
Integer division of x
by y
, changing x
in-place.
ipow
$x->ipow(BigNum) # => BigNum
$x->ipow(Scalar) # => BigNum
Raises x
to power y
, truncating x
and y
to integers, if necessarily.
bipow
$x->bipow(BigNum) # => BigNum
$x->bipow(Scalar) # => BigNum
Raises x
to power y
, changing x
in-place.
isqrt
$x->isqrt # => BigNum | Nan
Integer square root of x
. Returns Nan when x
is negative.
bisqrt
$x->bisqrt # => BigNum | Nan
Integer square root of x
, changing x
in-place. Promotes x
to Nan when x
is negative.
isqrtrem
$x->isqrtrem # => (BigNum, BigNum) | (Nan, Nan)
The integer part of the square root of x
and the remainder x - isqrt(x)**2
, which will be zero when <x> is a perfect square.
Returns (Nan,Nan) when x
is negative.
iroot
$x->iroot(BigNum) # => BigNum | Nan
$x->iroot(Scalar) # => BigNum | Nan
Nth integer root of x
.
Returns Nan when x
is negative and y
is even.
biroot
$x->biroot(BigNum) # => BigNum | Nan
$x->biroot(Scalar) # => BigNum | Nan
Nth integer root of x
, changing x
in-place. Promotes x
to Nan when x
is negative and y
is even.
irootrem
$x->irootrem(BigNum) # => (BigNum, BigNum) | (Nan, Nan)
$x->irootrem(Scalar) # => (BigNum, BigNum) | (Nan, Nan)
The nth integer part of the root of x
and the remainder x - iroot(x,y)**y
.
Returns (Nan,Nan) when x
is negative.
imod
$x->imod(BigNum) # => BigNum | Nan
$x->imod(Scalar) # => BigNum | Nan
Integer remainder of x
when is divided by y
. If necessary, x
and y
are implicitly truncated to integers. Nan is returned when y
is zero.
bimod
$x->bimod(BigNum) # => BigNum | Nan
$x->bimod(Scalar) # => BigNum | Nan
Sets x
to the remainder of x
divided by y
. If necessary, x
and y
are implicitly truncated to integers. Sets x
to Nan when y
is zero.
divmod
$x->divmod(BigNum) # => (BigNum, BigNum) | (Nan, Nan)
$x->divmod(Scalar) # => (BigNum, BigNum) | (Nan, Nan)
Returns the quotient and the remainder from division of x
by y
, where both are integers. When y
is zero, it returns two Nan values.
* Number theory
modinv
$x->modinv(BigNum) # => BigNum | Nan
$x->modinv(Scalar) # => BigNum | Nan
Computes the inverse of x
modulo y
and returns the result. If an inverse does not exists, the Nan value is returned.
modpow
$x->modpow(BigNum, BigNum) # => BigNum | Nan
$x->modpow(Scalar, Scalar) # => BigNum | Nan
$x->modpow(BigNum, Scalar) # => BigNum | Nan
$x->modpow(Scalar, BigNum) # => BigNum | Nan
Calculates (x ^ y) mod z
, where all three values are integers.
Returns Nan when the third argument is 0.
gcd
$x->gcd(BigNum) # => BigNum
$x->gcd(Scalar) # => BigNum
The greatest common divisor of x
and y
.
lcm
$x->lcd(BigNum) # => BigNum
$x->lcd(Scalar) # => BigNum
The least common multiple of x
and y
.
valuation
$n->valuation(BigNum) # => Scalar
$n->valuation(Scalar) # => Scalar
Returns the number of times n is divisible by k.
kronecker
$n->kronecker(BigNum) # => Scalar
$n->kronecker(Scalar) # => Scalar
Returns the Kronecker symbol (n|m), which is a generalization of the Jacobi symbol for all integers m.
is_psqr
$n->is_psqr # => Bool
Returns a true value when n
is a perfect square. When n
is not an integer, returns 0
.
is_ppow
$n->is_ppow # => Bool
Returns a true value when n
is a perfect power of some integer k
. When n
is not an integer, returns 0
.
is_pow
$n->is_pow(BigNum) # => Bool
$n->is_pow(Scalar) # => Bool
Return a true value when n
is a perfect power of a given integer k
. When n
is not an integer, returns 0
. On the other hand, when k
is not an integer, it will be truncated implicitly to an integer. If k
is not positive after truncation, 0
is returned.
A true value is returned iff there exists some integer a satisfying the equation: a^k = n.
Example:
100->is_pow(2) # true: 100 is a square (10^2)
125->is_pow(3) # true: 125 is a cube ( 5^3)
is_prime
$n->is_prime # => Scalar
$x->is_prime(BigNum) # => Scalar
$n->is_prime(Scalar) # => Scalar
Returns 2 if n
is definitely prime, 1 if n
is probably prime (without being certain), or 0 if n
is definitely composite. This method does some trial divisions, then some Miller-Rabin probabilistic primality tests. It also accepts an optional argument for specifying the accuracy of the test. By default, it uses an accuracy value of 20.
Reasonable accuracy values are between 15 and 50.
See also:
https://en.wikipedia.org/wiki/Miller–Rabin_primality_test
https://gmplib.org/manual/Number-Theoretic-Functions.html
next_prime
$n->next_prime # => BigNum
Returns the next prime after n
.
fac
$n->fac # => BigNum | Nan
Factorial of n
. Returns Nan when n
is negative. (1*2*3*...*n
)
bfac
$n->bfac # => BigNum | Nan
Factorial of n
, modifying n
in-place.
dfac
$n->dfac # => BigNum | Nan
Double factorial of n
. Returns Nan when n
is negative.
Example:
7->dfac # 1*3*5*7 = 105
8->dfac # 2*4*6*8 = 384
primorial
$n->primorial # => BigNum | Nan
Returns the product of all the primes less than or equal to n
.
fib
$n->fib # => BigNum | Nan
The n-th Fibonacci number. Returns Nan when n
is negative.
Defined as:
fib(0) = 0
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)
lucas
$n->lucas # => BigNum | Nan
The n-th Lucas number. Returns Nan when n
is negative.
Defined as:
lucas(0) = 2
lucas(1) = 1
lucas(n) = lucas(n-1) + lucas(n-2)
binomial
$n->binomial(BigNum) # => BigNum
$n->binomial(Scalar) # => BigNum
Calculates the binomial coefficient n over k, also called the "choose" function. The result is equivalent to:
( n ) n!
| | = -------
( k ) k!(n-k)!
* Bitwise operations
and
$x->and(BigNum) # => BigNum
$x->and(Scalar) # => BigNum
BigNum & BigNum # => BigNum
BigNum & Scalar # => BigNum
Scalar & BigNum # => BigNum
Integer logical-and operation.
band
$x->band(BigNum) # => BigNum
$x->band(Scalar) # => BigNum
BigNum &= BigNum # => BigNum
BigNum &= Scalar # => BigNum
Integer logical-and operation, changing x
in-place.
ior
$x->ior(BigNum) # => BigNum
$x->ior(Scalar) # => BigNum
BigNum | BigNum # => BigNum
BigNum | Scalar # => BigNum
Scalar | BigNum # => BigNum
Integer logical inclusive-or operation.
bior
$x->bior(BigNum) # => BigNum
$x->bior(Scalar) # => BigNum
BigNum |= BigNum # => BigNum
BigNum |= Scalar # => BigNum
Integer logical inclusive-or operation, changing x
in-place.
xor
$x->xor(BigNum) # => BigNum
$x->xor(Scalar) # => BigNum
BigNum ^ BigNum # => BigNum
BigNum ^ Scalar # => BigNum
Scalar ^ BigNum # => BigNum
Integer logical exclusive-or operation.
bxor
$x->bxor(BigNum) # => BigNum
$x->bxor(Scalar) # => BigNum
BigNum ^= BigNum # => BigNum
BigNum ^= Scalar # => BigNum
Integer logical exclusive-or operation, changing x
in-place.
not
$x->not # => BigNum
~BigNum # => BigNum
Integer logical-not operation. (The one's complement of x
).
bnot
$x->bnot # => BigNum
Integer logical-not operation, changing x
in-place.
lsft
$x->lsft(BigNum) # => BigNum
$x->lsft(Scalar) # => BigNum
BigNum << BigNum # => BigNum
BigNum << Scalar # => BigNum
Scalar << BigNum # => BigNum
Integer left-shift operation. (x * (2 ^ y)
)
blsft
$x->blsft(BigNum) # => BigNum
$x->blsft(Scalar) # => BigNum
BigNum <<= BigNum # => BigNum
BigNum <<= Scalar # => BigNum
Integer left-shift operation, changing x
in-place. Promotes x
to Nan when y
is negative. (x * (2 ^ y)
)
rsft
$x->rsft(BigNum) # => BigNum
$x->rsft(Scalar) # => BigNum
BigNum >> BigNum # => BigNum
BigNum >> Scalar # => BigNum
Scalar >> BigNum # => BigNum
Integer right-shift operation. (x / (2 ^ y)
)
brsft
$x->brsft(BigNum) # => BigNum
$x->brsft(Scalar) # => BigNum
BigNum >>= BigNum # => BigNum
BigNum >>= Scalar # => BigNum
Integer right-shift operation, changing x
in-place. (x / (2 ^ y)
)
popcount
$x->popcount # => Scalar
Returns the population count of x
, which is the number of 1 bits in the binary representation. When x
is negative, the population count of its absolute value is returned.
This method is also known as the Hamming weight value.
MISCELLANEOUS
This section includes various useful methods.
rand
$x->rand # => BigNum
$x->rand(BigNum) # => BigNum
$x->rand(Scalar) # => BigNum
Returns a pseudorandom floating-point value. When an additional argument is provided, it returns a number between x
and y
, otherwise, a number between 0
(inclusive) and x
(exclusive) is returned.
The PRNG behind this method is called the "Mersenne Twister". Although it generates pseudorandom numbers of very good quality, it is NOT cryptographically secure!
Example:
10->rand # a random number between 0 and 10 (exclusive)
10->rand(20) # a random number between 10 and 20 (exclusive)
seed
$n->seed # => BigNum
Reseeds the rand()
method with the value of n
, where n
can be any arbitrary large integer.
Returns back the original value of n
.
irand
$x->irand # => BigNum
$x->irand(BigNum) # => BigNum
$x->irand(Scalar) # => BigNum
Returns a pseudorandom integer. When an additional argument is provided, it returns an integer between x
and y-1
, otherwise, an integer between 0
(inclusive) and x
(exclusive) is returned.
The PRNG behind this method is called the "Mersenne Twister". Although it generates high-quality pseudorandom integers, it is NOT cryptographically secure!
Example:
10->irand # a random integer between 0 and 10 (exclusive)
10->irand(20) # a random integer between 10 and 20 (exclusive)
iseed
$n->iseed # => BigNum
Reseeds the irand()
method with the value of n
, where n
can be any arbitrary large integer.
Returns back the original value of n
.
copy
$x->copy # => BigNum
Returns a deep copy of x
.
floor
$x->floor # => BigNum
Returns x
if x
is an integer, otherwise it rounds x
towards -Infinity.
Example:
floor( 2.5) = 2
floor(-2.5) = -3
ceil
$x->ceil # => BigNum
Returns x
if x
is an integer, otherwise it rounds x
towards +Infinity.
Example:
ceil( 2.5) = 3
ceil(-2.5) = -2
int
$x->int # => BigNum
int($x) # => BigNum
Returns a truncated integer from the value of x
.
Example:
int( 2.5) = 2
int(-2.5) = -2
bint
$x->bint # => BigNum
Truncates x
to an integer in-place.
float
$x->float # => BigNum
$x->float(Scalar) # => BigNum
Returns a truncated number that fits inside number of bits specified as an argument. When no argument is specified or when the argument is undefined, the value of $Math::BigNum::PREC
will be used instead.
bfloat
$x->bfloat # => BigNum
$x->bfloat(Scalar) # => BigNum
Same as the method float
, except that x
is truncated in-place.
round
$x->round(BigNum) # => BigNum
$x->round(Scalar) # => BigNum
Rounds x
to the nth place. A negative argument rounds that many digits after the decimal point, while a positive argument rounds before the decimal point. This method uses the "round half to even" algorithm, which is the default rounding mode used in IEEE 754 computing functions and operators.
bround
$x->bround(BigNum) # => BigNum
$x->bround(Scalar) # => BigNum
Rounds x
in-place to nth places.
neg
$x->neg # => BigNum
-$x # => BigNum
Negative value of x
.
bneg
$x->bneg # => BigNum
Negative value of x
, changing x
in-place.
abs
$x->abs # => BigNum
abs($x) # => BigNum
Absolute value of x
.
Example:
abs(-42) = 42
abs( 42) = 42
babs
$x->babs # => BigNum
Absolute value of x
, changing x
in-place.
inc
$x->inc # => BigNum
Returns x + 1
.
binc
$x->binc # => BigNum
++$x # => BigNum
$x++ # => BigNum
Increments x
in-place by 1.
dec
$x->dec # => BigNum
Returns x - 1
.
bdec
$x->bdec # => BigNum
--$x # => BigNum
$x-- # => BigNum
Decrements x
in-place by 1.
* Introspection
is_zero
$x->is_zero # => Bool
Returns a true value when x
is 0.
is_one
$x->is_one # => Bool
Returns a true value when x
is +1.
is_mone
$x->is_mone # => Bool
Returns a true value when x
is -1.
is_pos
$x->is_pos # => Bool
Returns a true value when x
is greater than zero.
is_neg
$x->is_neg # => Bool
Returns a true value when x
is less than zero.
is_int
$x->is_int # => Bool
Returns a true value when x
is an integer.
is_real
$x->is_real # => Bool
Always returns a true value when invoked on a Math::BigNum object.
is_inf
$x->is_inf # => Bool
Always returns a false value when invoked on a Math::BigNum object.
is_nan
$x->is_nan # => Bool
Always returns a false value when invoked on a Math::BigNum object.
is_ninf
$x->is_ninf # => Bool
Always returns a false value when invoked on a Math::BigNum object.
is_odd
$x->is_odd # => Bool
Returns a true value when x
is NOT divisible by 2. Returns 0
if x
is NOT an integer.
is_even
$x->is_even # => Bool
Returns a true value when x
is divisible by 2. Returns 0
if x
is NOT an integer.
is_div
$x->is_div(BigNum) # => Bool
$x->is_div(Scalar) # => Bool
Returns a true value if x
is divisible by y
(i.e. when the result of division of x
by y
is an integer). False otherwise.
Example:
is_div(15, 3) = true
is_div(15, 4) = false
It is also defined for rational numbers, returning a true value when the quotient of division is an integer:
is_div(17, 3.4) = true # because: 17/3.4 = 5
This method is very efficient when the first argument is an integer and the second argument is a Perl integer.
sign
$x->sign # => Scalar
Returns -1
when x
is negative, 1
when x
is positive, and 0
when x
is zero.
length
$x->length # => Scalar
Returns the number of digits of x
in base 10 before the decimal point.
For x=-1234.56
, it returns 4
.
* Conversions
stringify
$x->stringify # => Scalar
Returns a string representing the value of x
, either as a base-10 integer, or a decimal expansion.
Example:
stringify(1/2) = "0.5"
stringify(100) = "100"
numify
$x->numify # => Scalar
Returns a Perl numerical scalar with the value of x
, truncated if needed.
boolify
$x->boolify # => Bool
Returns a true value when the number is not zero. False otherwise.
as_frac
$x->as_frac # => Scalar
Returns a string representing the number as a base-10 fraction.
Example:
as_frac(3.5) = "7/2"
as_frac(3.0) = "3/1"
as_rat
$x->as_rat # => Scalar
Almost the same as as_frac()
, except that integers are returned as they are, without adding a denominator of 1.
Example:
as_rat(3.5) = "7/2"
as_rat(3.0) = "3"
as_float
$x->as_float # => Scalar
$x->as_float(Scalar) # => Scalar
$x->as_float(BigNum) # => Scalar
Returns the self-number as a floating-point scalar. The method also accepts an optional argument for precision after the decimal point. When no argument is provided, it uses the default precision.
Example:
as_float(1/3, 4) = "0.3333"
If the self number is an integer, it will be returned as it is.
as_int
$x->as_int # => Scalar
$x->as_int(Scalar) # => Scalar
$x->as_int(BigNum) # => Scalar
Returns the self-number as an integer in a given base. When the base is omitted, it defaults to 10.
Example:
as_int(255) = "255"
as_int(255, 16) = "ff"
as_bin
$x->as_bin # => Scalar
Returns a string representing the value of x
in binary.
Example:
as_bin(42) = "101010"
as_oct
$x->as_oct # => Scalar
Returns a string representing the value of x
in octal.
Example:
as_oct(42) = "52"
as_hex
$x->as_hex # => Scalar
Returns a string representing the value of x
in hexadecimal.
Example:
as_hex(42) = "2a"
in_base
$x->in_base(Scalar) # => Scalar
Returns a string with the value of x
in a given base, where the base can range from 2 to 36 inclusive. If x
is not an integer, the result is returned in rationalized form.
Example:
in_base(42, 3) = "1120"
in_base(12.34, 36) = "h5/1e"
deg2rad
$x->deg2rad # => BigNum
Returns the value of x
converted from degrees to radians.
Example:
deg2rad(180) = pi
rad2deg
$x->rad2deg # => BigNum
Returns the value of x
converted from radians to degrees.
Example:
rad2deg(pi) = 180
* Dissections
digits
$x->digits # => (Scalar, Scalar, ...)
$x->digits(Scalar) # => (Scalar, Scalar, ...)
Returns a list with the digits of x
in a given base. When no base is specified, it defaults to base 10.
Only the absolute integer part of x
is considered.
Example:
digits(-1234.56) = (1,2,3,4)
digits(4095, 16) = ('f','f','f')
numerator
$x->numerator # => BigNum
Returns a copy of the numerator as signed BigNum.
denominator
$x->denominator # => BigNum
Returns a copy of the denominator as positive BigNum.
parts
$x->parts # => (BigNum, BigNum)
Returns a copy of the numerator (signed) and a copy of the denominator (unsigned) as BigNum objects.
Example:
parts(-0.75) = (-3, 4)
* Comparisons
eq
$x->eq(BigNum) # => Bool
$x->eq(Scalar) # => Bool
$x == $y # => Bool
Equality check: returns a true value when x
and y
are equal.
ne
$x->ne(BigNum) # => Bool
$x->ne(Scalar) # => Bool
$x != $y # => Bool
Inequality check: returns a true value when x
and y
are not equal.
gt
$x->gt(BigNum) # => Bool
$x->gt(Scalar) # => Bool
BigNum > BigNum # => Bool
BigNum > Scalar # => Bool
Scalar > BigNum # => Bool
Returns a true value when x
is greater than y
.
ge
$x->ge(BigNum) # => Bool
$x->ge(Scalar) # => Bool
BigNum >= BigNum # => Bool
BigNum >= Scalar # => Bool
Scalar >= BigNum # => Bool
Returns a true value when x
is equal or greater than y
.
lt
$x->lt(BigNum) # => Bool
$x->lt(Scalar) # => Bool
BigNum < BigNum # => Bool
BigNum < Scalar # => Bool
Scalar < BigNum # => Bool
Returns a true value when x
is less than y
.
le
$x->le(BigNum) # => Bool
$x->le(Scalar) # => Bool
BigNum <= BigNum # => Bool
BigNum <= Scalar # => Bool
Scalar <= BigNum # => Bool
Returns a true value when x
is equal or less than y
.
cmp
$x->cmp(BigNum) # => Scalar
$x->cmp(Scalar) # => Scalar
BigNum <=> BigNum # => Scalar
BigNum <=> Scalar # => Scalar
Scalar <=> BigNum # => Scalar
Compares x
to y
and returns a negative value when x
is less than y
, 0 when x
and y
are equal, and a positive value when x
is greater than y
.
acmp
$x->acmp(BigNum) # => Scalar
cmp(Scalar, BigNum) # => Scalar
Compares the absolute values of x
and y
. Returns a negative value when the absolute value of x
is less than the absolute value of y
, 0 when the absolute value of x
is equal to the absolute value of y
, and a positive value when the absolute value of x
is greater than the absolute value of y
.
min
$x->min(BigNum) # => BigNum
Returns x
if x
is lower than y
. Returns y
otherwise.
max
$x->max(BigNum) # => BigNum
Returns x
if x
is greater than y
. Returns y
otherwise.
AUTHOR
Daniel Șuteu, <trizenx at gmail.com>
BUGS
Please report any bugs or feature requests to bug-math-bignum at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-BigNum. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Math::BigNum
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
GitHub
ACKNOWLEDGEMENTS
Rounding
Special cases and NaN
What Every Computer Scientist Should Know About FloatingPoint Arithmetic
http://www.cl.cam.ac.uk/teaching/1011/FPComp/floatingmath.pdf
Wolfram|Alpha
SEE ALSO
Fast math libraries
Math::GMP - High speed arbitrary size integer math.
Math::GMPz - perl interface to the GMP library's integer (mpz) functions.
Math::GMPq - perl interface to the GMP library's rational (mpq) functions.
Math::MPFR - perl interface to the MPFR (floating point) library.
Portable math libraries
Math::BigInt - Arbitrary size integer/float math package.
Math::BigFloat - Arbitrary size floating point math package.
Math::BigRat - Arbitrary big rational numbers.
Math utilities
Math::Prime::Util - Utilities related to prime numbers, including fast sieves and factoring.
LICENSE AND COPYRIGHT
Copyright 2016-2017 Daniel Șuteu.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.