Skip to content

Releases: brick/math

0.5.1

05 Jul 11:17
Compare
Choose a tag to compare

New method: BigNumber::toScale()

This allows to convert any BigNumber to a BigDecimal with a given scale, using rounding if necessary.

0.5.0

04 Jul 20:43
Compare
Choose a tag to compare

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

0.4.2

16 Jun 23:25
Compare
Choose a tag to compare

New method: BigDecimal::stripTrailingZeros()

0.4.1

12 Jun 22:21
Compare
Choose a tag to compare

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

0.4.0

12 Jun 10:52
Compare
Choose a tag to compare

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.

0.3.4

11 Jun 23:12
Compare
Choose a tag to compare

New methods:

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

0.3.3

07 Jun 22:18
Compare
Choose a tag to compare

Fix toString() not handling negative numbers.

0.3.2

07 Jun 12:56
Compare
Choose a tag to compare

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

0.3.1

05 Jun 21:05
Compare
Choose a tag to compare

Minor performance improvements

0.3.0

04 Jun 22:23
Compare
Choose a tag to compare

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