Skip to content

Releases: brick/math

0.15.0

20 Feb 15:47

Choose a tag to compare

💥 Breaking changes

  • floating-point inputs are no longer accepted by of() and arithmetic methods, use of((string) $float) to get the same behaviour as before (#105)
  • BigRational is now always simplified to lowest terms: all operations, including of() and ofFraction(), now return a fraction in its simplest form (e.g. 2/3 instead of 4/6)
  • BigDecimal::dividedBy() now requires the $scale parameter
  • BigInteger::sqrt() and BigDecimal::sqrt() now default to RoundingMode::Unnecessary, explicitly pass RoundingMode::Down to get the previous behaviour
  • BigInteger::mod() now uses Euclidean modulo semantics: the modulus must be strictly positive, and the result is always non-negative; this change aligns with Java's BigInteger.mod() behaviour
  • BigInteger::mod(), modInverse() and modPow() now throw InvalidArgumentException (instead of NegativeNumberException) for negative modulus/exponent arguments
  • MathException is now an interface instead of a class
  • BigDecimal::getPrecision() now returns 1 for zero values
  • BigNumber::min(), max() and sum() now throw an ArgumentCountError when called with no arguments (previously threw InvalidArgumentException)
  • BigInteger::randomBits() and randomRange() now throw RandomSourceException when random byte generation fails or returns invalid data

Deprecated API elements removed:

  • deprecated method BigInteger::testBit() has been removed, use isBitSet() instead
  • deprecated method BigInteger::gcdMultiple() has been removed, use gcdAll() instead
  • deprecated method BigDecimal::exactlyDividedBy() has been removed, use dividedByExact() instead
  • deprecated method BigDecimal::getIntegralPart() has been removed (will be re-introduced as returning BigInteger in 0.16)
  • deprecated method BigDecimal::getFractionalPart() has been removed (will be re-introduced as returning BigDecimal with a different meaning in 0.16)
  • deprecated method BigDecimal::stripTrailingZeros() has been removed, use strippedOfTrailingZeros() instead
  • deprecated method BigRational::nd() has been removed, use ofFraction() instead
  • deprecated method BigRational::quotient() has been removed, use getIntegralPart() instead
  • deprecated method BigRational::remainder() has been removed, use $number->getNumerator()->remainder($number->getDenominator()) instead
  • deprecated method BigRational::quotientAndRemainder() has been removed, use $number->getNumerator()->quotientAndRemainder($number->getDenominator()) instead
  • deprecated RoundingMode upper snake case constants (e.g. HALF_UP) have been removed, use the pascal case version (e.g. HalfUp) instead

The following breaking changes only affect you if you're using named arguments:

  • BigInteger::mod() now uses $modulus as the parameter name
  • BigInteger::modInverse() now uses $modulus as the parameter name
  • BigInteger::modPow() now uses $exponent and $modulus as parameter names
  • BigInteger::shiftedLeft() now uses $bits as the parameter name
  • BigInteger::shiftedRight() now uses $bits as the parameter name
  • BigInteger::isBitSet() now uses $bitIndex as the parameter name
  • BigInteger::randomBits() now uses $bitCount as the parameter name
  • BigDecimal::withPointMovedLeft() now uses $places as the parameter name
  • BigDecimal::withPointMovedRight() now uses $places as the parameter name

The following breaking changes are unlikely to affect you:

  • DivisionByZeroException::modulusMustNotBeZero() has been renamed to zeroModulus()
  • DivisionByZeroException::denominatorMustNotBeZero() has been renamed to zeroDenominator()
  • IntegerOverflowException::toIntOverflow() has been renamed to integerOutOfRange()
  • RoundingNecessaryException::roundingNecessary() has been removed

🗑️ Deprecations

  • Method BigRational::simplified() is deprecated, as it is now a no-op

New features

  • BigInteger::power(), BigDecimal::power() and BigRational::power() no longer enforce an exponent limit
  • BigInteger::shiftedLeft() and BigInteger::shiftedRight() no longer enforce a limit on the number of bits
  • BigRational::power() now accepts negative exponents
  • New exception: InvalidArgumentException for invalid argument errors
  • New exception: NoInverseException for modular inverse errors
  • New exception: RandomSourceException for random source errors

👌 Improvements

  • Narrowed parameter and return types with static analysis annotations (#108 by @simPod)

0.14.8

10 Feb 14:36

Choose a tag to compare

🗑️ Deprecations

  • Method BigInteger::testBit() is deprecated, use isBitSet() instead

New features

  • New method: BigInteger::isBitSet() (replaces testBit())
  • New method: BigNumber::toString() (alias of magic method __toString())

👌 Improvements

  • Performance optimization of BigRational comparison methods
  • More exceptions have been documented with @throws annotations

0.14.7

07 Feb 10:59

Choose a tag to compare

New features

  • clamp() is now available on the base BigNumber class

👌 Improvements

  • Improved @throws exception documentation

0.14.6

05 Feb 08:11

Choose a tag to compare

🗑️ Deprecations

  • Not passing a $scale to BigDecimal::dividedBy() is deprecated; $scale will be required in 0.15

👌 Improvements

  • BigRational::toFloat() never returns NAN anymore

0.14.5

03 Feb 18:15

Choose a tag to compare

🗑️ Deprecations

  • Not passing a rounding mode to BigInteger::sqrt() and BigDecimal::sqrt() triggers a deprecation notice: the default rounding mode will change from Down to Unnecessary in 0.15

New features

  • BigInteger::sqrt() and BigDecimal::sqrt() now support rounding
  • abs() and negated() methods are now available on the base BigNumber class

👌 Improvements

  • Alphabet is now checked for duplicate characters in BigInteger::(from|to)ArbitraryBase()
  • BigNumber::ofNullable() is now marked as @pure

0.14.4

02 Feb 17:01

Choose a tag to compare

🗑️ Deprecations

  • Passing a negative modulus to BigInteger::mod() is deprecated to align with Euclidean modulo semantics; it will throw InvalidArgumentException in 0.15
  • Method BigDecimal::stripTrailingZeros() is deprecated, use strippedOfTrailingZeros() instead

New features

  • BigInteger::modPow() now accepts negative bases
  • New method: BigDecimal::strippedOfTrailingZeros() (replaces stripTrailingZeros())

👌 Improvements

  • clamp() methods are now marked as @pure

0.14.3

01 Feb 15:22

Choose a tag to compare

New features

  • New method: BigInteger::lcm()
  • New method: BigInteger::lcmAll()
  • New method: BigRational::toRepeatingDecimalString()

🐛 Bug fixes

  • BigInteger::gcdAll() / gcdMultiple() could return a negative result when used with a single negative number

0.14.2

30 Jan 14:05

Choose a tag to compare

🗑️ Deprecations

  • Passing float values to of() or arithmetic methods is deprecated and will be removed in 0.15; cast to string explicitly to preserve the previous behaviour (#105)
  • Accessing RoundingMode enum cases through upper snake case (e.g. HALF_UP) is deprecated, use the pascal case version (e.g. HalfUp) instead
  • Method BigInteger::gcdMultiple() is deprecated, use gcdAll() instead
  • Method BigDecimal::exactlyDividedBy() is deprecated, use dividedByExact() instead
  • Method BigDecimal::getIntegralPart() is deprecated (will be removed in 0.15, and re-introduced as returning BigInteger in 0.16)
  • Method BigDecimal::getFractionalPart() is deprecated (will be removed in 0.15, and re-introduced as returning BigDecimal with a different meaning in 0.16)
  • Method BigRational::nd() is deprecated, use ofFraction() instead
  • Method BigRational::quotient() is deprecated, use getIntegralPart() instead
  • Method BigRational::remainder() is deprecated, use $number->getNumerator()->remainder($number->getDenominator()) instead
  • Method BigRational::quotientAndRemainder() is deprecated, use $number->getNumerator()->quotientAndRemainder($number->getDenominator()) instead

New features

  • New method: BigInteger::gcdAll() (replaces gcdMultiple())
  • New method: BigRational::clamp()
  • New method: BigRational::ofFraction() (replaces nd())
  • New method: BigRational::getIntegralPart() (replaces quotient())
  • New method: BigRational::getFractionalPart()

👌 Improvements

  • BigInteger::modInverse() now accepts BigNumber|int|float|string instead of just BigInteger
  • BigInteger::gcdMultiple() now accepts BigNumber|int|float|string instead of just BigInteger

🐛 Bug fixes

  • BigInteger::clamp() and BigDecimal::clamp() now throw an exception on inverted bounds, instead of returning an incorrect result

0.14.1

24 Nov 14:42

Choose a tag to compare

New features

  • New method: BigNumber::ofNullable() (#94 by @mrkh995)

Compatibility fixes

0.14.0

29 Aug 12:50

Choose a tag to compare

New features

  • New methods: BigInteger::clamp() and BigDecimal::clamp() (#96 by @JesterIruka)

Improvements

  • All pure methods in BigNumber classes are now marked as @pure for better static analysis

💥 Breaking changes

  • Minimum PHP version is now 8.2
  • BigNumber classes are now readonly
  • BigNumber is now marked as sealed: it must not be extended outside of this package
  • Exception classes are now final