Arbitrary-precision arithmetic library for PHP
MIT License
Bot releases are hidden (Show)
Published by BenMorel over 9 years ago
New method: BigNumber::toScale()
This allows to convert any BigNumber
to a BigDecimal
with a given scale, using rounding if necessary.
Published by BenMorel over 9 years ago
New features
BigNumber
interface for all classes, with the following methods:
sign()
and derived methods (isZero()
, isPositive()
, ...)compareTo()
and derived methods (isEqualTo()
, isGreaterThan()
, ...) that work across different BigNumber
typestoBigInteger()
, toBigDecimal()
, toBigRational
() conversion methodstoInteger()
and toFloat()
conversion methods to native typesof()
behaviour: every class now accepts any type of number, provided that it can be safely converted to the current typeBigDecimal::exactlyDividedBy()
; this method automatically computes the scale of the result, provided that the division yields a finite number of digitsBigRational::quotient()
and remainder()
DivisionByZeroException
, RoundingNecessaryException
, NumberFormatException
zero()
, one()
and ten()
available in all classesBigInteger::dividedBy()
This release also comes with many performance improvements.
Breaking changes
BigInteger
:
getSign()
is renamed to sign()
toString()
is renamed to toBase()
BigInteger::dividedBy()
now throws an exception by default if the remainder is not zero; use quotient()
to get the previous behaviourBigDecimal
:
getSign()
is renamed to sign()
getUnscaledValue()
is renamed to unscaledValue()
getScale()
is renamed to scale()
getIntegral()
is renamed to integral()
getFraction()
is renamed to fraction()
divideAndRemainder()
is renamed to quotientAndRemainder()
dividedBy()
now takes a mandatory $scale
parameter before the rounding modetoBigInteger()
does not accept a $roundingMode
parameter anymoretoBigRational()
does not simplify the fraction anymore; explicitly add ->simplified()
to get the previous behaviourBigRational
:
getSign()
is renamed to sign()
getNumerator()
is renamed to numerator()
getDenominator()
is renamed to denominator()
of()
is renamed to nd()
, while parse()
is renamed to of()
ArithmeticException
is moved to an Exception\
sub-namespaceof()
factory methods now throw NumberFormatException
instead of InvalidArgumentException
Published by BenMorel over 9 years ago
New method: BigDecimal::stripTrailingZeros()
Published by BenMorel over 9 years ago
Introducing a BigRational
class, to perform calculations on fractions of any size.
Published by BenMorel over 9 years ago
Rounding modes have been removed from BigInteger
, and are now a concept specific to BigDecimal
.
BigInteger::dividedBy()
now always returns the quotient of the division.
Published by BenMorel over 9 years ago
New methods:
BigInteger::remainder()
returns the remainder of a division onlyBigInteger::gcd()
returns the greatest common divisor of two numbersPublished by BenMorel over 9 years ago
Fix toString()
not handling negative numbers.
Published by BenMorel over 9 years ago
BigInteger
and BigDecimal
now have a getSign()
method that returns:
-1
if the number is negative0
if the number is zero1
if the number is positivePublished by BenMorel over 9 years ago
Minor performance improvements
Published by BenMorel over 9 years ago
The $roundingMode
and $scale
parameters have been swapped in BigDecimal::dividedBy()
.
Published by BenMorel over 9 years ago
Stronger immutability guarantee for BigInteger
and BigDecimal
.
So far, it would have been possible to break immutability of these classes by calling the unserialize()
internal function. This release fixes that.
Published by BenMorel over 9 years ago
Added BigDecimal::divideAndRemainder()
Published by BenMorel over 9 years ago
min()
and max()
do not accept an array
anymore, but a variable number of parametersPublished by BenMorel about 10 years ago
BigInteger::power()
Published by BenMorel about 10 years ago
First beta release.