math

Arbitrary-precision arithmetic library for PHP

MIT License

Downloads
306.3M
Stars
1.8K
Committers
13

Bot releases are hidden (Show)

math - 0.5.1

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.

math - 0.5.0

Published by BenMorel over 9 years ago

New features

  • Common 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 types
    • toBigInteger(), toBigDecimal(), toBigRational() conversion methods
    • toInteger() and toFloat() conversion methods to native types
  • Unified of() behaviour: every class now accepts any type of number, provided that it can be safely converted to the current type
  • New method: BigDecimal::exactlyDividedBy(); this method automatically computes the scale of the result, provided that the division yields a finite number of digits
  • New methods: BigRational::quotient() and remainder()
  • Fine-grained exceptions: DivisionByZeroException, RoundingNecessaryException, NumberFormatException
  • Factory methods zero(), one() and ten() available in all classes
  • Rounding mode reintroduced in BigInteger::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 behaviour
  • BigDecimal:
    • 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 mode
    • toBigInteger() does not accept a $roundingMode parameter anymore
    • toBigRational() does not simplify the fraction anymore; explicitly add ->simplified() to get the previous behaviour
  • BigRational:
    • 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()
  • Miscellaneous:
    • ArithmeticException is moved to an Exception\ sub-namespace
    • of() factory methods now throw NumberFormatException instead of InvalidArgumentException
math - 0.4.2

Published by BenMorel over 9 years ago

New method: BigDecimal::stripTrailingZeros()

math - 0.4.1

Published by BenMorel over 9 years ago

Introducing a BigRational class, to perform calculations on fractions of any size.

math - 0.4.0

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.

math - 0.3.4

Published by BenMorel over 9 years ago

New methods:

  • BigInteger::remainder() returns the remainder of a division only
  • BigInteger::gcd() returns the greatest common divisor of two numbers
math - 0.3.3

Published by BenMorel over 9 years ago

Fix toString() not handling negative numbers.

math - 0.3.2

Published by BenMorel over 9 years ago

BigInteger and BigDecimal now have a getSign() method that returns:

  • -1 if the number is negative
  • 0 if the number is zero
  • 1 if the number is positive
math - 0.3.1

Published by BenMorel over 9 years ago

Minor performance improvements

math - 0.3.0

Published by BenMorel over 9 years ago

The $roundingMode and $scale parameters have been swapped in BigDecimal::dividedBy().

math - 0.2.2

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.

math - 0.2.1

Published by BenMorel over 9 years ago

Added BigDecimal::divideAndRemainder()

math - 0.2.0

Published by BenMorel over 9 years ago

  • min() and max() do not accept an array anymore, but a variable number of parameters
  • minimum PHP version is now 5.6
  • continuous integration with PHP 7
math - 0.1.1

Published by BenMorel about 10 years ago

  • Added BigInteger::power()
  • Added HHVM support
math - 0.1.0

Published by BenMorel about 10 years ago

First beta release.