BlueGit

projects-timfalken-com microchess

Files

microchess / web / lib / push / vendor / brick / math / CHANGELOG.md

CHANGELOG.md

CHANGELOG.md 34.9 KiB Download Raw

Changelog

All notable changes to this project will be documented in this file.

0.20.0 - 2026-08-28

πŸ’₯ Breaking changes

  • Deprecated exception class UnsupportedPlatformException has been removed, catch PlatformException instead

The following breaking change only affects you if you specifically catch DivisionByZeroException around calls to of() or to any method accepting strings:

  • of() now throws NumberFormatException instead of DivisionByZeroException when the string is a fraction with a denominator of zero, such as '2/0'

✨ New features

  • New methods: parse() and parseNullable() safely parse untrusted input, by restricting the allowed syntax and limiting the number of digits
  • New enum: NumberSyntax lists the syntax features that parse() can accept, with constants for the most common combinations

πŸ› Bug fixes

  • of() no longer throws PlatformException on malformed input with many digits, crafted to trigger heavy backtracking in its parser; such input now throws NumberFormatException as documented

πŸ‘Œ Improvements

  • NumberFormatException messages now escape control and non-ASCII characters, and truncate values longer than 40 bytes, instead of copying the raw input into the message

0.19.1 - 2026-08-08

✨ New features

  • New exception class: PlatformException (replaces UnsupportedPlatformException)
  • PlatformException is now thrown when preg_match() fails due to improper PHP configuration
  • PlatformException is now thrown when PHP_INT_SIZE is an unsupported value

πŸ—‘οΈ Deprecations

  • Exception class UnsupportedPlatformException is deprecated; catch PlatformException instead

0.19.0 - 2026-07-30

✨ New features

  • New rounding mode: RoundingMode::HalfOdd
  • New method: RoundingMode::fromNativeRoundingMode() converts from a native PHP RoundingMode enum (PHP 8.4+)

0.18.0 - 2026-06-14

πŸ’₯ Breaking changes

The following breaking change only affects you if you're using named arguments:

  • BigInteger::fromBytes() now uses $bytes as the parameter name

πŸ› Bug fixes

  • of() no longer accepts a trailing newline (\n) in the input string; such input now throws NumberFormatException
  • of() now consistently throws NumberFormatException for exponents too large to process, instead of IntegerOverflowException in some cases
  • BigInteger::fromBase() now reports the invalid character with its original case in the NumberFormatException message, instead of lower-casing it

⚑️ Performance improvements

  • BigInteger::gcd() no longer exhausts memory on large inputs when the GMP extension is not installed
  • BigInteger::modInverse() no longer exhausts memory on large inputs, and is faster when the GMP extension is not installed

πŸ‘Œ Static analysis improvements

  • Narrowed parameter and return types with static analysis annotations:
  • nthRoot()'s $n is now positive-int
  • BigInteger::toBase(), toArbitraryBase(), toBytes() and BigRational::toRepeatingDecimalString() now return non-empty-string

0.17.2 - 2026-05-25

✨ New features

  • New methods: BigInteger::nthRoot() and BigDecimal::nthRoot() compute the nth root of a number (#113 by @Pablo1Gustavo)

0.17.1 - 2026-04-19

πŸ‘Œ Improvements

  • More precise float approximations in BigRational::toFloat()

0.17.0 - 2026-03-17

πŸ’₯ Breaking changes

  • Deprecated method BigDecimal::hasNonZeroFractionalPart() has been removed, use ! $number->getFractionalPart()->isZero() instead
  • Exception constructors and factory methods are now @internal

✨ Compatibility improvements

  • BigDecimal::fromFloatExact() now supports 32-bit PHP

0.16.2 - 2026-03-15

✨ New features

New methods to create a BigDecimal from a float value:

  • BigDecimal::fromFloatExact()
  • BigDecimal::fromFloatShortest()

0.16.1 - 2026-03-09

πŸ‘Œ Improvements

  • Add @return non-empty-string to toString(), jsonSerialize() and __toString() (#111 by @vudaltsov)

0.16.0 - 2026-03-06

πŸ’₯ Breaking changes

  • BigInteger::getLowestSetBit() now returns null instead of -1 when the number is zero
  • Deprecated method BigRational::simplified() has been removed, as it is now a no-op

✨ New features

  • New method: BigDecimal::getIntegralPart() returns the integral part as BigInteger (this method existed with a different signature in version 0.14, and was removed in 0.15)
  • New method: BigDecimal::getFractionalPart() returns the fractional part as BigDecimal (this method existed with a different signature and meaning in version 0.14, and was removed in 0.15)

πŸ—‘οΈ Deprecations

  • Method BigDecimal::hasNonZeroFractionalPart() is deprecated, use ->getFractionalPart()->isZero() instead

0.15.0 - 2026-02-20

πŸ’₯ 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 - 2026-02-10

πŸ—‘οΈ 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 - 2026-02-07

✨ New features

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

πŸ‘Œ Improvements

  • Improved @throws exception documentation

0.14.6 - 2026-02-05

πŸ—‘οΈ 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 - 2026-02-03

πŸ—‘οΈ 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 - 2026-02-02

πŸ—‘οΈ 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 - 2026-02-01

✨ 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 - 2026-01-30

πŸ—‘οΈ 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

  • All exceptions thrown by the library now implement a common MathException interface
  • 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 - 2025-11-24

✨ New features

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

✨ Compatibility fixes

  • Fixed warnings on PHP 8.5 (#101 and #102 by @julien-boudry)

0.14.0 - 2025-08-29

✨ 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

0.13.1 - 2025-03-29

✨ Improvements

  • __toString() methods of BigInteger and BigDecimal are now type-hinted as returning numeric-string instead of string (#90 by @vudaltsov)

0.13.0 - 2025-03-03

πŸ’₯ Breaking changes

  • BigDecimal::ofUnscaledValue() no longer throws an exception if the scale is negative
  • MathException now extends RuntimeException instead of Exception; this reverts the change introduced in version 0.11.0 (#82)

✨ New features

  • BigDecimal::ofUnscaledValue() allows a negative scale (and converts the values to create a zero scale number)

0.12.3 - 2025-02-28

✨ New features

  • BigDecimal::getPrecision() Returns the number of significant digits in a decimal number

0.12.2 - 2025-02-26

⚑️ Performance improvements

  • Division in NativeCalculator is now faster for small divisors, thanks to @Izumi-kun in #87.

πŸ‘Œ Improvements

  • Add missing RoundingNecessaryException to the @throws annotation of BigNumber::of()

0.12.1 - 2023-11-29

⚑️ Performance improvements

0.12.0 - 2023-11-26

πŸ’₯ Breaking changes

  • Minimum PHP version is now 8.1
  • RoundingMode is now an enum; if you're type-hinting rounding modes, you need to type-hint against RoundingMode instead of int now
  • BigNumber classes do not implement the Serializable interface anymore (they use the new custom object serialization mechanism)
  • The following breaking changes only affect you if you're creating your own BigNumber subclasses:
  • the return type of BigNumber::of() is now static
  • BigNumber has a new abstract method from()
  • all public and protected functions of BigNumber are now final

0.11.0 - 2023-01-16

πŸ’₯ Breaking changes

  • Minimum PHP version is now 8.0
  • Methods accepting a union of types are now strongly typed*
  • MathException now extends Exception instead of RuntimeException

* You may now run into type errors if you were passing Stringable objects to of() or any of the methods internally calling of(), with strict_types enabled. You can fix this by casting Stringable objects to string first.

0.10.2 - 2022-08-11

πŸ‘Œ Improvements

  • BigRational::toFloat() now simplifies the fraction before performing division (#73) thanks to @olsavmic

0.10.1 - 2022-08-02

✨ New features

  • BigInteger::gcdMultiple() returns the GCD of multiple BigInteger numbers

0.10.0 - 2022-06-18

πŸ’₯ Breaking changes

  • Minimum PHP version is now 7.4

0.9.3 - 2021-08-15

πŸš€ Compatibility with PHP 8.1

  • Support for custom object serialization; this removes a warning on PHP 8.1 due to the Serializable interface being deprecated (#60) thanks @TRowbotham

0.9.2 - 2021-01-20

πŸ› Bug fix

  • Incorrect results could be returned when using the BCMath calculator, with a default scale set with bcscale(), on PHP >= 7.2 (#55).

0.9.1 - 2020-08-19

✨ New features

  • BigInteger::not() returns the bitwise NOT value

πŸ› Bug fixes

  • BigInteger::toBytes() could return an incorrect binary representation for some numbers
  • The bitwise operations and(), or(), xor() on BigInteger could return an incorrect result when the GMP extension is not available

0.9.0 - 2020-08-18

πŸ‘Œ Improvements

  • BigNumber::of() now accepts .123 and 123. formats, both of which return a BigDecimal

πŸ’₯ Breaking changes

  • Deprecated method BigInteger::powerMod() has been removed - use modPow() instead
  • Deprecated method BigInteger::parse() has been removed - use fromBase() instead

0.8.17 - 2020-08-19

πŸ› Bug fix

  • BigInteger::toBytes() could return an incorrect binary representation for some numbers
  • The bitwise operations and(), or(), xor() on BigInteger could return an incorrect result when the GMP extension is not available

0.8.16 - 2020-08-18

πŸš‘ Critical fix

  • This version reintroduces the deprecated BigInteger::parse() method, that has been removed by mistake in version 0.8.9 and should have lasted for the whole 0.8 release cycle.

✨ New features

  • BigInteger::modInverse() calculates a modular multiplicative inverse
  • BigInteger::fromBytes() creates a BigInteger from a byte string
  • BigInteger::toBytes() converts a BigInteger to a byte string
  • BigInteger::randomBits() creates a pseudo-random BigInteger of a given bit length
  • BigInteger::randomRange() creates a pseudo-random BigInteger between two bounds

πŸ’© Deprecations

  • BigInteger::powerMod() is now deprecated in favour of modPow()

0.8.15 - 2020-04-15

πŸ› Fixes

  • added missing ext-json requirement, due to BigNumber implementing JsonSerializable

⚑️ Optimizations

  • additional optimization in BigInteger::remainder()

0.8.14 - 2020-02-18

✨ New features

  • BigInteger::getLowestSetBit() returns the index of the rightmost one bit

0.8.13 - 2020-02-16

✨ New features

  • BigInteger::isEven() tests whether the number is even
  • BigInteger::isOdd() tests whether the number is odd
  • BigInteger::testBit() tests if a bit is set
  • BigInteger::getBitLength() returns the number of bits in the minimal representation of the number

0.8.12 - 2020-02-03

πŸ› οΈ Maintenance release

Classes are now annotated for better static analysis with psalm.

This is a maintenance release: no bug fixes, no new features, no breaking changes.

0.8.11 - 2020-01-23

✨ New feature

BigInteger::powerMod() performs a power-with-modulo operation. Useful for crypto.

0.8.10 - 2020-01-21

✨ New feature

BigInteger::mod() returns the modulo of two numbers. The modulo differs from the remainder when the signs of the operands are different.

0.8.9 - 2020-01-08

⚑️ Performance improvements

A few additional optimizations in BigInteger and BigDecimal when one of the operands can be returned as is. Thanks to @tomtomsen in #24.

0.8.8 - 2019-04-25

πŸ› Bug fixes

  • BigInteger::toBase() could return an empty string for zero values (BCMath & Native calculators only, GMP calculator unaffected)

✨ New features

  • BigInteger::toArbitraryBase() converts a number to an arbitrary base, using a custom alphabet
  • BigInteger::fromArbitraryBase() converts a string in an arbitrary base, using a custom alphabet, back to a number

These methods can be used as the foundation to convert strings between different bases/alphabets, using BigInteger as an intermediate representation.

πŸ’© Deprecations

  • BigInteger::parse() is now deprecated in favour of fromBase()

BigInteger::fromBase() works the same way as parse(), with 2 minor differences:

  • the $base parameter is required, it does not default to 10
  • it throws a NumberFormatException instead of an InvalidArgumentException when the number is malformed

0.8.7 - 2019-04-20

Improvements

  • Safer conversion from float when using custom locales
  • Much faster NativeCalculator implementation πŸš€

You can expect at least a 3x performance improvement for common arithmetic operations when using the library on systems without GMP or BCMath; it gets exponentially faster on multiplications with a high number of digits. This is due to calculations now being performed on whole blocks of digits (the block size depending on the platform, 32-bit or 64-bit) instead of digit-by-digit as before.

0.8.6 - 2019-04-11

New method

BigNumber::sum() returns the sum of one or more numbers.

0.8.5 - 2019-02-12

Bug fix: of() factory methods could fail when passing a float in environments using a LC_NUMERIC locale with a decimal separator other than '.' (#20).

Thanks @manowark πŸ‘

0.8.4 - 2018-12-07

New method

BigDecimal::sqrt() calculates the square root of a decimal number, to a given scale.

0.8.3 - 2018-12-06

New method

BigInteger::sqrt() calculates the square root of a number (thanks @peter279k).

New exception

NegativeNumberException is thrown when calling sqrt() on a negative number.

0.8.2 - 2018-11-08

Performance update

  • Further improvement of toInt() performance
  • NativeCalculator can now perform some multiplications more efficiently

0.8.1 - 2018-11-07

Performance optimization of toInt() methods.

0.8.0 - 2018-10-13

Breaking changes

The following deprecated methods have been removed. Use the new method name instead:

Method removedReplacement method
BigDecimal::getIntegral()BigDecimal::getIntegralPart()
BigDecimal::getFraction()BigDecimal::getFractionalPart()

---

New features

BigInteger has been augmented with 5 new methods for bitwise operations:

New methodDescription
and()performs a bitwise AND operation on two numbers
or()performs a bitwise OR operation on two numbers
xor()performs a bitwise XOR operation on two numbers
shiftedLeft()returns the number shifted left by a number of bits
shiftedRight()returns the number shifted right by a number of bits

Thanks to @DASPRiD πŸ‘

0.7.3 - 2018-08-20

New method: BigDecimal::hasNonZeroFractionalPart()

Renamed/deprecated methods:

  • BigDecimal::getIntegral() has been renamed to getIntegralPart() and is now deprecated
  • BigDecimal::getFraction() has been renamed to getFractionalPart() and is now deprecated

0.7.2 - 2018-07-21

Performance update

BigInteger::parse() and toBase() now use GMP's built-in base conversion features when available.

0.7.1 - 2018-03-01

This is a maintenance release, no code has been changed.

  • When installed with --no-dev, the autoloader does not autoload tests anymore
  • Tests and other files unnecessary for production are excluded from the dist package

This will help make installations more compact.

0.7.0 - 2017-10-02

Methods renamed:

  • BigNumber:sign() has been renamed to getSign()
  • BigDecimal::unscaledValue() has been renamed to getUnscaledValue()
  • BigDecimal::scale() has been renamed to getScale()
  • BigDecimal::integral() has been renamed to getIntegral()
  • BigDecimal::fraction() has been renamed to getFraction()
  • BigRational::numerator() has been renamed to getNumerator()
  • BigRational::denominator() has been renamed to getDenominator()

Classes renamed:

  • ArithmeticException has been renamed to MathException

0.6.2 - 2017-10-02

The base class for all exceptions is now MathException. ArithmeticException has been deprecated, and will be removed in 0.7.0.

0.6.1 - 2017-10-02

A number of methods have been renamed:

  • BigNumber:sign() is deprecated; use getSign() instead
  • BigDecimal::unscaledValue() is deprecated; use getUnscaledValue() instead
  • BigDecimal::scale() is deprecated; use getScale() instead
  • BigDecimal::integral() is deprecated; use getIntegral() instead
  • BigDecimal::fraction() is deprecated; use getFraction() instead
  • BigRational::numerator() is deprecated; use getNumerator() instead
  • BigRational::denominator() is deprecated; use getDenominator() instead

The old methods will be removed in version 0.7.0.

0.6.0 - 2017-08-25

  • Minimum PHP version is now 7.1; for PHP 5.6 and PHP 7.0 support, use version 0.5
  • Deprecated method BigDecimal::withScale() has been removed; use toScale() instead
  • Method BigNumber::toInteger() has been renamed to toInt()

0.5.4 - 2016-10-17

BigNumber classes now implement JsonSerializable. The JSON output is always a string.

0.5.3 - 2016-03-31

This is a bugfix release. Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.

0.5.2 - 2015-08-06

The $scale parameter of BigDecimal::dividedBy() is now optional again.

0.5.1 - 2015-07-05

New method: BigNumber::toScale()

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

0.5.0 - 2015-07-04

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.3 - 2016-03-31

Backport of two bug fixes from the 0.5 branch:

  • BigInteger::parse() did not always throw InvalidArgumentException as expected
  • Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.

0.4.2 - 2015-06-16

New method: BigDecimal::stripTrailingZeros()

0.4.1 - 2015-06-12

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

0.4.0 - 2015-06-12

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.5 - 2016-03-31

Backport of two bug fixes from the 0.5 branch:

  • BigInteger::parse() did not always throw InvalidArgumentException as expected
  • Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.

0.3.4 - 2015-06-11

New methods:

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

0.3.3 - 2015-06-07

Fix toString() not handling negative numbers.

0.3.2 - 2015-06-07

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 - 2015-06-05

Minor performance improvements

0.3.0 - 2015-06-04

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

0.2.2 - 2015-06-04

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.

0.2.1 - 2015-06-02

Added BigDecimal::divideAndRemainder()

0.2.0 - 2015-05-22

  • 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

0.1.1 - 2014-09-01

  • Added BigInteger::power()
  • Added HHVM support

0.1.0 - 2014-08-31

First beta release.

Source
1# Changelog
2
3All notable changes to this project will be documented in this file.
4
5## [0.20.0](https://github.com/brick/math/releases/tag/0.20.0) - 2026-08-28
6
7πŸ’₯ **Breaking changes**
8
9- Deprecated exception class `UnsupportedPlatformException` has been removed, catch `PlatformException` instead
10
11The following breaking change only affects you if you specifically catch `DivisionByZeroException` around calls to `of()` or to any method accepting strings:
12
13- `of()` now throws `NumberFormatException` instead of `DivisionByZeroException` when the string is a fraction with a denominator of zero, such as `'2/0'`
14
15✨ **New features**
16
17- New methods: `parse()` and `parseNullable()` safely parse untrusted input, by restricting the allowed syntax and limiting the number of digits
18- New enum: `NumberSyntax` lists the syntax features that `parse()` can accept, with constants for the most common combinations
19
20πŸ› **Bug fixes**
21
22- `of()` no longer throws `PlatformException` on malformed input with many digits, crafted to trigger heavy backtracking in its parser; such input now throws `NumberFormatException` as documented
23
24πŸ‘Œ **Improvements**
25
26- `NumberFormatException` messages now escape control and non-ASCII characters, and truncate values longer than 40 bytes, instead of copying the raw input into the message
27
28## [0.19.1](https://github.com/brick/math/releases/tag/0.19.1) - 2026-08-08
29
30✨ **New features**
31
32- New exception class: `PlatformException` (replaces `UnsupportedPlatformException`)
33- `PlatformException` is now thrown when `preg_match()` fails due to improper PHP configuration
34- `PlatformException` is now thrown when `PHP_INT_SIZE` is an unsupported value
35
36πŸ—‘οΈ **Deprecations**
37
38- Exception class `UnsupportedPlatformException` is deprecated; catch `PlatformException` instead
39
40## [0.19.0](https://github.com/brick/math/releases/tag/0.19.0) - 2026-07-30
41
42✨ **New features**
43
44- New rounding mode: `RoundingMode::HalfOdd`
45- New method: `RoundingMode::fromNativeRoundingMode()` converts from a native PHP `RoundingMode` enum (PHP 8.4+)
46
47## [0.18.0](https://github.com/brick/math/releases/tag/0.18.0) - 2026-06-14
48
49πŸ’₯ **Breaking changes**
50
51The following breaking change only affects you if you're using named arguments:
52
53- `BigInteger::fromBytes()` now uses `$bytes` as the parameter name
54
55πŸ› **Bug fixes**
56
57- `of()` no longer accepts a trailing newline (`\n`) in the input string; such input now throws `NumberFormatException`
58- `of()` now consistently throws `NumberFormatException` for exponents too large to process, instead of `IntegerOverflowException` in some cases
59- `BigInteger::fromBase()` now reports the invalid character with its original case in the `NumberFormatException` message, instead of lower-casing it
60
61⚑️ **Performance improvements**
62
63- `BigInteger::gcd()` no longer exhausts memory on large inputs when the GMP extension is not installed
64- `BigInteger::modInverse()` no longer exhausts memory on large inputs, and is faster when the GMP extension is not installed
65
66πŸ‘Œ **Static analysis improvements**
67
68- Narrowed parameter and return types with static analysis annotations:
69 - `nthRoot()`'s `$n` is now `positive-int`
70 - `BigInteger::toBase()`, `toArbitraryBase()`, `toBytes()` and `BigRational::toRepeatingDecimalString()` now return `non-empty-string`
71
72## [0.17.2](https://github.com/brick/math/releases/tag/0.17.2) - 2026-05-25
73
74✨ **New features**
75
76- New methods: `BigInteger::nthRoot()` and `BigDecimal::nthRoot()` compute the nth root of a number (#113 by @Pablo1Gustavo)
77
78## [0.17.1](https://github.com/brick/math/releases/tag/0.17.1) - 2026-04-19
79
80πŸ‘Œ **Improvements**
81
82- More precise `float` approximations in `BigRational::toFloat()`
83
84## [0.17.0](https://github.com/brick/math/releases/tag/0.17.0) - 2026-03-17
85
86πŸ’₯ **Breaking changes**
87
88- Deprecated method `BigDecimal::hasNonZeroFractionalPart()` has been removed, use `! $number->getFractionalPart()->isZero()` instead
89- Exception constructors and factory methods are now `@internal`
90
91✨ **Compatibility improvements**
92
93- `BigDecimal::fromFloatExact()` now supports 32-bit PHP
94
95## [0.16.2](https://github.com/brick/math/releases/tag/0.16.2) - 2026-03-15
96
97✨ **New features**
98
99New methods to create a `BigDecimal` from a `float` value:
100
101- `BigDecimal::fromFloatExact()`
102- `BigDecimal::fromFloatShortest()`
103
104## [0.16.1](https://github.com/brick/math/releases/tag/0.16.1) - 2026-03-09
105
106πŸ‘Œ **Improvements**
107
108- Add `@return non-empty-string` to `toString()`, `jsonSerialize()` and `__toString()` (#111 by @vudaltsov)
109
110## [0.16.0](https://github.com/brick/math/releases/tag/0.16.0) - 2026-03-06
111
112πŸ’₯ **Breaking changes**
113
114- **`BigInteger::getLowestSetBit()` now returns `null` instead of `-1` when the number is zero**
115- Deprecated method `BigRational::simplified()` has been removed, as it is now a no-op
116
117✨ **New features**
118
119- New method: `BigDecimal::getIntegralPart()` returns the integral part as `BigInteger` (this method existed with a different signature in version 0.14, and was removed in 0.15)
120- New method: `BigDecimal::getFractionalPart()` returns the fractional part as `BigDecimal` (this method existed with a different signature and meaning in version 0.14, and was removed in 0.15)
121
122πŸ—‘οΈ **Deprecations**
123
124- Method `BigDecimal::hasNonZeroFractionalPart()` is deprecated, use `->getFractionalPart()->isZero()` instead
125
126## [0.15.0](https://github.com/brick/math/releases/tag/0.15.0) - 2026-02-20
127
128πŸ’₯ **Breaking changes**
129
130- **floating-point inputs are no longer accepted by `of()` and arithmetic methods**, use `of((string) $float)` to get the same behaviour as before (#105)
131- **`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`)
132- **`BigDecimal::dividedBy()` now requires the `$scale` parameter**
133- **`BigInteger::sqrt()` and `BigDecimal::sqrt()` now default to `RoundingMode::Unnecessary`**, explicitly pass `RoundingMode::Down` to get the previous behaviour
134- **`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
135- **`BigInteger::mod()`, `modInverse()` and `modPow()` now throw `InvalidArgumentException` (instead of `NegativeNumberException`) for negative modulus/exponent arguments**
136- **`MathException` is now an interface** instead of a class
137- **`BigDecimal::getPrecision()` now returns `1` for zero values**
138- `BigNumber::min()`, `max()` and `sum()` now throw an `ArgumentCountError` when called with no arguments (previously threw `InvalidArgumentException`)
139- `BigInteger::randomBits()` and `randomRange()` now throw `RandomSourceException` when random byte generation fails or returns invalid data
140
141Deprecated API elements removed:
142
143- deprecated method `BigInteger::testBit()` has been removed, use `isBitSet()` instead
144- deprecated method `BigInteger::gcdMultiple()` has been removed, use `gcdAll()` instead
145- deprecated method `BigDecimal::exactlyDividedBy()` has been removed, use `dividedByExact()` instead
146- deprecated method `BigDecimal::getIntegralPart()` has been removed (will be re-introduced as returning `BigInteger` in 0.16)
147- deprecated method `BigDecimal::getFractionalPart()` has been removed (will be re-introduced as returning `BigDecimal` with a different meaning in 0.16)
148- deprecated method `BigDecimal::stripTrailingZeros()` has been removed, use `strippedOfTrailingZeros()` instead
149- deprecated method `BigRational::nd()` has been removed, use `ofFraction()` instead
150- deprecated method `BigRational::quotient()` has been removed, use `getIntegralPart()` instead
151- deprecated method `BigRational::remainder()` has been removed, use `$number->getNumerator()->remainder($number->getDenominator())` instead
152- deprecated method `BigRational::quotientAndRemainder()` has been removed, use `$number->getNumerator()->quotientAndRemainder($number->getDenominator())` instead
153- deprecated `RoundingMode` upper snake case constants (e.g. `HALF_UP`) have been removed, use the pascal case version (e.g. `HalfUp`) instead
154
155The following breaking changes only affect you if you're using named arguments:
156
157- `BigInteger::mod()` now uses `$modulus` as the parameter name
158- `BigInteger::modInverse()` now uses `$modulus` as the parameter name
159- `BigInteger::modPow()` now uses `$exponent` and `$modulus` as parameter names
160- `BigInteger::shiftedLeft()` now uses `$bits` as the parameter name
161- `BigInteger::shiftedRight()` now uses `$bits` as the parameter name
162- `BigInteger::isBitSet()` now uses `$bitIndex` as the parameter name
163- `BigInteger::randomBits()` now uses `$bitCount` as the parameter name
164- `BigDecimal::withPointMovedLeft()` now uses `$places` as the parameter name
165- `BigDecimal::withPointMovedRight()` now uses `$places` as the parameter name
166
167The following breaking changes are unlikely to affect you:
168
169- `DivisionByZeroException::modulusMustNotBeZero()` has been renamed to `zeroModulus()`
170- `DivisionByZeroException::denominatorMustNotBeZero()` has been renamed to `zeroDenominator()`
171- `IntegerOverflowException::toIntOverflow()` has been renamed to `integerOutOfRange()`
172- `RoundingNecessaryException::roundingNecessary()` has been removed
173
174πŸ—‘οΈ **Deprecations**
175
176- Method `BigRational::simplified()` is deprecated, as it is now a no-op
177
178✨ **New features**
179
180- `BigInteger::power()`, `BigDecimal::power()` and `BigRational::power()` no longer enforce an exponent limit
181- `BigInteger::shiftedLeft()` and `BigInteger::shiftedRight()` no longer enforce a limit on the number of bits
182- `BigRational::power()` now accepts negative exponents
183- New exception: `InvalidArgumentException` for invalid argument errors
184- New exception: `NoInverseException` for modular inverse errors
185- New exception: `RandomSourceException` for random source errors
186
187πŸ‘Œ **Improvements**
188
189- Narrowed parameter and return types with static analysis annotations (#108 by @simPod)
190
191## [0.14.8](https://github.com/brick/math/releases/tag/0.14.8) - 2026-02-10
192
193πŸ—‘οΈ **Deprecations**
194
195- Method `BigInteger::testBit()` is deprecated, use `isBitSet()` instead
196
197✨ **New features**
198
199- New method: `BigInteger::isBitSet()` (replaces `testBit()`)
200- New method: `BigNumber::toString()` (alias of magic method `__toString()`)
201
202πŸ‘Œ **Improvements**
203
204- Performance optimization of `BigRational` comparison methods
205- More exceptions have been documented with `@throws` annotations
206
207## [0.14.7](https://github.com/brick/math/releases/tag/0.14.7) - 2026-02-07
208
209✨ **New features**
210
211- `clamp()` is now available on the base `BigNumber` class
212
213πŸ‘Œ **Improvements**
214
215- Improved `@throws` exception documentation
216
217## [0.14.6](https://github.com/brick/math/releases/tag/0.14.6) - 2026-02-05
218
219πŸ—‘οΈ **Deprecations**
220
221- Not passing a `$scale` to `BigDecimal::dividedBy()` is deprecated; **`$scale` will be required in 0.15**
222
223πŸ‘Œ **Improvements**
224
225- `BigRational::toFloat()` never returns `NAN` anymore
226
227## [0.14.5](https://github.com/brick/math/releases/tag/0.14.5) - 2026-02-03
228
229πŸ—‘οΈ **Deprecations**
230
231- 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**
232
233✨ **New features**
234
235- `BigInteger::sqrt()` and `BigDecimal::sqrt()` now support rounding
236- `abs()` and `negated()` methods are now available on the base `BigNumber` class
237
238πŸ‘Œ **Improvements**
239
240- Alphabet is now checked for duplicate characters in `BigInteger::(from|to)ArbitraryBase()`
241- `BigNumber::ofNullable()` is now marked as `@pure`
242
243## [0.14.4](https://github.com/brick/math/releases/tag/0.14.4) - 2026-02-02
244
245πŸ—‘οΈ **Deprecations**
246
247- Passing a negative modulus to `BigInteger::mod()` is deprecated to align with Euclidean modulo semantics; it will throw `InvalidArgumentException` in 0.15
248- Method `BigDecimal::stripTrailingZeros()` is deprecated, use `strippedOfTrailingZeros()` instead
249
250✨ **New features**
251
252- `BigInteger::modPow()` now accepts negative bases
253- New method: `BigDecimal::strippedOfTrailingZeros()` (replaces `stripTrailingZeros()`)
254
255πŸ‘Œ **Improvements**
256
257- `clamp()` methods are now marked as `@pure`
258
259## [0.14.3](https://github.com/brick/math/releases/tag/0.14.3) - 2026-02-01
260
261✨ **New features**
262
263- New method: `BigInteger::lcm()`
264- New method: `BigInteger::lcmAll()`
265- New method: `BigRational::toRepeatingDecimalString()`
266
267πŸ› **Bug fixes**
268
269- `BigInteger::gcdAll()` / `gcdMultiple()` could return a negative result when used with a single negative number
270
271## [0.14.2](https://github.com/brick/math/releases/tag/0.14.2) - 2026-01-30
272
273πŸ—‘οΈ **Deprecations**
274
275- **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)
276- **Accessing `RoundingMode` enum cases through upper snake case (e.g. `HALF_UP`) is deprecated**, use the pascal case version (e.g. `HalfUp`) instead
277- Method `BigInteger::gcdMultiple()` is deprecated, use `gcdAll()` instead
278- Method `BigDecimal::exactlyDividedBy()` is deprecated, use `dividedByExact()` instead
279- Method `BigDecimal::getIntegralPart()` is deprecated (will be removed in 0.15, and re-introduced as returning `BigInteger` in 0.16)
280- Method `BigDecimal::getFractionalPart()` is deprecated (will be removed in 0.15, and re-introduced as returning `BigDecimal` with a different meaning in 0.16)
281- Method `BigRational::nd()` is deprecated, use `ofFraction()` instead
282- Method `BigRational::quotient()` is deprecated, use `getIntegralPart()` instead
283- Method `BigRational::remainder()` is deprecated, use `$number->getNumerator()->remainder($number->getDenominator())` instead
284- Method `BigRational::quotientAndRemainder()` is deprecated, use `$number->getNumerator()->quotientAndRemainder($number->getDenominator())` instead
285
286✨ **New features**
287
288- New method: `BigInteger::gcdAll()` (replaces `gcdMultiple()`)
289- New method: `BigRational::clamp()`
290- New method: `BigRational::ofFraction()` (replaces `nd()`)
291- New method: `BigRational::getIntegralPart()` (replaces `quotient()`)
292- New method: `BigRational::getFractionalPart()`
293
294πŸ‘Œ **Improvements**
295
296- All exceptions thrown by the library now implement a common `MathException` interface
297- `BigInteger::modInverse()` now accepts `BigNumber|int|float|string` instead of just `BigInteger`
298- `BigInteger::gcdMultiple()` now accepts `BigNumber|int|float|string` instead of just `BigInteger`
299
300πŸ› **Bug fixes**
301
302- `BigInteger::clamp()` and `BigDecimal::clamp()` now throw an exception on inverted bounds, instead of returning an incorrect result
303
304## [0.14.1](https://github.com/brick/math/releases/tag/0.14.1) - 2025-11-24
305
306✨ **New features**
307
308- New method: `BigNumber::ofNullable()` (#94 by @mrkh995)
309
310✨ **Compatibility fixes**
311
312- Fixed warnings on PHP 8.5 (#101 and #102 by @julien-boudry)
313
314## [0.14.0](https://github.com/brick/math/releases/tag/0.14.0) - 2025-08-29
315
316✨ **New features**
317
318- New methods: `BigInteger::clamp()` and `BigDecimal::clamp()` (#96 by @JesterIruka)
319
320✨ **Improvements**
321
322- All pure methods in `BigNumber` classes are now marked as `@pure` for better static analysis
323
324πŸ’₯ **Breaking changes**
325
326- Minimum PHP version is now 8.2
327- `BigNumber` classes are now `readonly`
328- `BigNumber` is now marked as sealed: it must not be extended outside of this package
329- Exception classes are now `final`
330
331## [0.13.1](https://github.com/brick/math/releases/tag/0.13.1) - 2025-03-29
332
333✨ **Improvements**
334
335- `__toString()` methods of `BigInteger` and `BigDecimal` are now type-hinted as returning `numeric-string` instead of `string` (#90 by @vudaltsov)
336
337## [0.13.0](https://github.com/brick/math/releases/tag/0.13.0) - 2025-03-03
338
339πŸ’₯ **Breaking changes**
340
341- `BigDecimal::ofUnscaledValue()` no longer throws an exception if the scale is negative
342- `MathException` now extends `RuntimeException` instead of `Exception`; this reverts the change introduced in version `0.11.0` (#82)
343
344✨ **New features**
345
346- `BigDecimal::ofUnscaledValue()` allows a negative scale (and converts the values to create a zero scale number)
347
348## [0.12.3](https://github.com/brick/math/releases/tag/0.12.3) - 2025-02-28
349
350✨ **New features**
351
352- `BigDecimal::getPrecision()` Returns the number of significant digits in a decimal number
353
354## [0.12.2](https://github.com/brick/math/releases/tag/0.12.2) - 2025-02-26
355
356⚑️ **Performance improvements**
357
358- Division in `NativeCalculator` is now faster for small divisors, thanks to [@Izumi-kun](https://github.com/Izumi-kun) in [#87](https://github.com/brick/math/pull/87).
359
360πŸ‘Œ **Improvements**
361
362- Add missing `RoundingNecessaryException` to the `@throws` annotation of `BigNumber::of()`
363
364## [0.12.1](https://github.com/brick/math/releases/tag/0.12.1) - 2023-11-29
365
366⚑️ **Performance improvements**
367
368- `BigNumber::of()` is now faster, thanks to [@SebastienDug](https://github.com/SebastienDug) in [#77](https://github.com/brick/math/pull/77).
369
370## [0.12.0](https://github.com/brick/math/releases/tag/0.12.0) - 2023-11-26
371
372πŸ’₯ **Breaking changes**
373
374- Minimum PHP version is now 8.1
375- `RoundingMode` is now an `enum`; if you're type-hinting rounding modes, you need to type-hint against `RoundingMode` instead of `int` now
376- `BigNumber` classes do not implement the `Serializable` interface anymore (they use the [new custom object serialization mechanism](https://wiki.php.net/rfc/custom_object_serialization))
377- The following breaking changes only affect you if you're creating your own `BigNumber` subclasses:
378 - the return type of `BigNumber::of()` is now `static`
379 - `BigNumber` has a new abstract method `from()`
380 - all `public` and `protected` functions of `BigNumber` are now `final`
381
382## [0.11.0](https://github.com/brick/math/releases/tag/0.11.0) - 2023-01-16
383
384πŸ’₯ **Breaking changes**
385
386- Minimum PHP version is now 8.0
387- Methods accepting a union of types are now strongly typed<sup>*</sup>
388- `MathException` now extends `Exception` instead of `RuntimeException`
389
390<sup>* You may now run into type errors if you were passing `Stringable` objects to `of()` or any of the methods
391internally calling `of()`, with `strict_types` enabled. You can fix this by casting `Stringable` objects to `string`
392first.</sup>
393
394## [0.10.2](https://github.com/brick/math/releases/tag/0.10.2) - 2022-08-11
395
396πŸ‘Œ **Improvements**
397
398- `BigRational::toFloat()` now simplifies the fraction before performing division (#73) thanks to @olsavmic
399
400## [0.10.1](https://github.com/brick/math/releases/tag/0.10.1) - 2022-08-02
401
402✨ **New features**
403
404- `BigInteger::gcdMultiple()` returns the GCD of multiple `BigInteger` numbers
405
406## [0.10.0](https://github.com/brick/math/releases/tag/0.10.0) - 2022-06-18
407
408πŸ’₯ **Breaking changes**
409
410- Minimum PHP version is now 7.4
411
412## [0.9.3](https://github.com/brick/math/releases/tag/0.9.3) - 2021-08-15
413
414πŸš€ **Compatibility with PHP 8.1**
415
416- Support for custom object serialization; this removes a warning on PHP 8.1 due to the `Serializable` interface being deprecated (#60) thanks @TRowbotham
417
418## [0.9.2](https://github.com/brick/math/releases/tag/0.9.2) - 2021-01-20
419
420πŸ› **Bug fix**
421
422- Incorrect results could be returned when using the BCMath calculator, with a default scale set with `bcscale()`, on PHP >= 7.2 (#55).
423
424## [0.9.1](https://github.com/brick/math/releases/tag/0.9.1) - 2020-08-19
425
426✨ **New features**
427
428- `BigInteger::not()` returns the bitwise `NOT` value
429
430πŸ› **Bug fixes**
431
432- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers
433- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available
434
435## [0.9.0](https://github.com/brick/math/releases/tag/0.9.0) - 2020-08-18
436
437πŸ‘Œ **Improvements**
438
439- `BigNumber::of()` now accepts `.123` and `123.` formats, both of which return a `BigDecimal`
440
441πŸ’₯ **Breaking changes**
442
443- Deprecated method `BigInteger::powerMod()` has been removed - use `modPow()` instead
444- Deprecated method `BigInteger::parse()` has been removed - use `fromBase()` instead
445
446## [0.8.17](https://github.com/brick/math/releases/tag/0.8.17) - 2020-08-19
447
448πŸ› **Bug fix**
449
450- `BigInteger::toBytes()` could return an incorrect binary representation for some numbers
451- The bitwise operations `and()`, `or()`, `xor()` on `BigInteger` could return an incorrect result when the GMP extension is not available
452
453## [0.8.16](https://github.com/brick/math/releases/tag/0.8.16) - 2020-08-18
454
455πŸš‘ **Critical fix**
456
457- This version reintroduces the deprecated `BigInteger::parse()` method, that has been removed by mistake in version `0.8.9` and should have lasted for the whole `0.8` release cycle.
458
459✨ **New features**
460
461- `BigInteger::modInverse()` calculates a modular multiplicative inverse
462- `BigInteger::fromBytes()` creates a `BigInteger` from a byte string
463- `BigInteger::toBytes()` converts a `BigInteger` to a byte string
464- `BigInteger::randomBits()` creates a pseudo-random `BigInteger` of a given bit length
465- `BigInteger::randomRange()` creates a pseudo-random `BigInteger` between two bounds
466
467πŸ’© **Deprecations**
468
469- `BigInteger::powerMod()` is now deprecated in favour of `modPow()`
470
471## [0.8.15](https://github.com/brick/math/releases/tag/0.8.15) - 2020-04-15
472
473πŸ› **Fixes**
474
475- added missing `ext-json` requirement, due to `BigNumber` implementing `JsonSerializable`
476
477⚑️ **Optimizations**
478
479- additional optimization in `BigInteger::remainder()`
480
481## [0.8.14](https://github.com/brick/math/releases/tag/0.8.14) - 2020-02-18
482
483✨ **New features**
484
485- `BigInteger::getLowestSetBit()` returns the index of the rightmost one bit
486
487## [0.8.13](https://github.com/brick/math/releases/tag/0.8.13) - 2020-02-16
488
489✨ **New features**
490
491- `BigInteger::isEven()` tests whether the number is even
492- `BigInteger::isOdd()` tests whether the number is odd
493- `BigInteger::testBit()` tests if a bit is set
494- `BigInteger::getBitLength()` returns the number of bits in the minimal representation of the number
495
496## [0.8.12](https://github.com/brick/math/releases/tag/0.8.12) - 2020-02-03
497
498πŸ› οΈ **Maintenance release**
499
500Classes are now annotated for better static analysis with [psalm](https://psalm.dev/).
501
502This is a maintenance release: no bug fixes, no new features, no breaking changes.
503
504## [0.8.11](https://github.com/brick/math/releases/tag/0.8.11) - 2020-01-23
505
506✨ **New feature**
507
508`BigInteger::powerMod()` performs a power-with-modulo operation. Useful for crypto.
509
510## [0.8.10](https://github.com/brick/math/releases/tag/0.8.10) - 2020-01-21
511
512✨ **New feature**
513
514`BigInteger::mod()` returns the **modulo** of two numbers. The *modulo* differs from the *remainder* when the signs of the operands are different.
515
516## [0.8.9](https://github.com/brick/math/releases/tag/0.8.9) - 2020-01-08
517
518⚑️ **Performance improvements**
519
520A few additional optimizations in `BigInteger` and `BigDecimal` when one of the operands can be returned as is. Thanks to @tomtomsen in #24.
521
522## [0.8.8](https://github.com/brick/math/releases/tag/0.8.8) - 2019-04-25
523
524πŸ› **Bug fixes**
525
526- `BigInteger::toBase()` could return an empty string for zero values (BCMath & Native calculators only, GMP calculator unaffected)
527
528✨ **New features**
529
530- `BigInteger::toArbitraryBase()` converts a number to an arbitrary base, using a custom alphabet
531- `BigInteger::fromArbitraryBase()` converts a string in an arbitrary base, using a custom alphabet, back to a number
532
533These methods can be used as the foundation to convert strings between different bases/alphabets, using BigInteger as an intermediate representation.
534
535πŸ’© **Deprecations**
536
537- `BigInteger::parse()` is now deprecated in favour of `fromBase()`
538
539`BigInteger::fromBase()` works the same way as `parse()`, with 2 minor differences:
540
541- the `$base` parameter is required, it does not default to `10`
542- it throws a `NumberFormatException` instead of an `InvalidArgumentException` when the number is malformed
543
544## [0.8.7](https://github.com/brick/math/releases/tag/0.8.7) - 2019-04-20
545
546**Improvements**
547
548- Safer conversion from `float` when using custom locales
549- **Much faster** `NativeCalculator` implementation πŸš€
550
551You can expect **at least a 3x performance improvement** for common arithmetic operations when using the library on systems without GMP or BCMath; it gets exponentially faster on multiplications with a high number of digits. This is due to calculations now being performed on whole blocks of digits (the block size depending on the platform, 32-bit or 64-bit) instead of digit-by-digit as before.
552
553## [0.8.6](https://github.com/brick/math/releases/tag/0.8.6) - 2019-04-11
554
555**New method**
556
557`BigNumber::sum()` returns the sum of one or more numbers.
558
559## [0.8.5](https://github.com/brick/math/releases/tag/0.8.5) - 2019-02-12
560
561**Bug fix**: `of()` factory methods could fail when passing a `float` in environments using a `LC_NUMERIC` locale with a decimal separator other than `'.'` (#20).
562
563Thanks @manowark πŸ‘
564
565## [0.8.4](https://github.com/brick/math/releases/tag/0.8.4) - 2018-12-07
566
567**New method**
568
569`BigDecimal::sqrt()` calculates the square root of a decimal number, to a given scale.
570
571## [0.8.3](https://github.com/brick/math/releases/tag/0.8.3) - 2018-12-06
572
573**New method**
574
575`BigInteger::sqrt()` calculates the square root of a number (thanks @peter279k).
576
577**New exception**
578
579`NegativeNumberException` is thrown when calling `sqrt()` on a negative number.
580
581## [0.8.2](https://github.com/brick/math/releases/tag/0.8.2) - 2018-11-08
582
583**Performance update**
584
585- Further improvement of `toInt()` performance
586- `NativeCalculator` can now perform some multiplications more efficiently
587
588## [0.8.1](https://github.com/brick/math/releases/tag/0.8.1) - 2018-11-07
589
590Performance optimization of `toInt()` methods.
591
592## [0.8.0](https://github.com/brick/math/releases/tag/0.8.0) - 2018-10-13
593
594**Breaking changes**
595
596The following deprecated methods have been removed. Use the new method name instead:
597
598| Method removed | Replacement method |
599| --- | --- |
600| `BigDecimal::getIntegral()` | `BigDecimal::getIntegralPart()` |
601| `BigDecimal::getFraction()` | `BigDecimal::getFractionalPart()` |
602
603---
604
605**New features**
606
607`BigInteger` has been augmented with 5 new methods for bitwise operations:
608
609| New method | Description |
610| --- | --- |
611| `and()` | performs a bitwise `AND` operation on two numbers |
612| `or()` | performs a bitwise `OR` operation on two numbers |
613| `xor()` | performs a bitwise `XOR` operation on two numbers |
614| `shiftedLeft()` | returns the number shifted left by a number of bits |
615| `shiftedRight()` | returns the number shifted right by a number of bits |
616
617Thanks to @DASPRiD πŸ‘
618
619## [0.7.3](https://github.com/brick/math/releases/tag/0.7.3) - 2018-08-20
620
621**New method:** `BigDecimal::hasNonZeroFractionalPart()`
622
623**Renamed/deprecated methods:**
624
625- `BigDecimal::getIntegral()` has been renamed to `getIntegralPart()` and is now deprecated
626- `BigDecimal::getFraction()` has been renamed to `getFractionalPart()` and is now deprecated
627
628## [0.7.2](https://github.com/brick/math/releases/tag/0.7.2) - 2018-07-21
629
630**Performance update**
631
632`BigInteger::parse()` and `toBase()` now use GMP's built-in base conversion features when available.
633
634## [0.7.1](https://github.com/brick/math/releases/tag/0.7.1) - 2018-03-01
635
636This is a maintenance release, no code has been changed.
637
638- When installed with `--no-dev`, the autoloader does not autoload tests anymore
639- Tests and other files unnecessary for production are excluded from the dist package
640
641This will help make installations more compact.
642
643## [0.7.0](https://github.com/brick/math/releases/tag/0.7.0) - 2017-10-02
644
645Methods renamed:
646
647- `BigNumber:sign()` has been renamed to `getSign()`
648- `BigDecimal::unscaledValue()` has been renamed to `getUnscaledValue()`
649- `BigDecimal::scale()` has been renamed to `getScale()`
650- `BigDecimal::integral()` has been renamed to `getIntegral()`
651- `BigDecimal::fraction()` has been renamed to `getFraction()`
652- `BigRational::numerator()` has been renamed to `getNumerator()`
653- `BigRational::denominator()` has been renamed to `getDenominator()`
654
655Classes renamed:
656
657- `ArithmeticException` has been renamed to `MathException`
658
659## [0.6.2](https://github.com/brick/math/releases/tag/0.6.2) - 2017-10-02
660
661The base class for all exceptions is now `MathException`.
662`ArithmeticException` has been deprecated, and will be removed in 0.7.0.
663
664## [0.6.1](https://github.com/brick/math/releases/tag/0.6.1) - 2017-10-02
665
666A number of methods have been renamed:
667
668- `BigNumber:sign()` is deprecated; use `getSign()` instead
669- `BigDecimal::unscaledValue()` is deprecated; use `getUnscaledValue()` instead
670- `BigDecimal::scale()` is deprecated; use `getScale()` instead
671- `BigDecimal::integral()` is deprecated; use `getIntegral()` instead
672- `BigDecimal::fraction()` is deprecated; use `getFraction()` instead
673- `BigRational::numerator()` is deprecated; use `getNumerator()` instead
674- `BigRational::denominator()` is deprecated; use `getDenominator()` instead
675
676The old methods will be removed in version 0.7.0.
677
678## [0.6.0](https://github.com/brick/math/releases/tag/0.6.0) - 2017-08-25
679
680- Minimum PHP version is now [7.1](https://gophp71.org/); for PHP 5.6 and PHP 7.0 support, use version `0.5`
681- Deprecated method `BigDecimal::withScale()` has been removed; use `toScale()` instead
682- Method `BigNumber::toInteger()` has been renamed to `toInt()`
683
684## [0.5.4](https://github.com/brick/math/releases/tag/0.5.4) - 2016-10-17
685
686`BigNumber` classes now implement [JsonSerializable](http://php.net/manual/en/class.jsonserializable.php).
687The JSON output is always a string.
688
689## [0.5.3](https://github.com/brick/math/releases/tag/0.5.3) - 2016-03-31
690
691This is a bugfix release. Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
692
693## [0.5.2](https://github.com/brick/math/releases/tag/0.5.2) - 2015-08-06
694
695The `$scale` parameter of `BigDecimal::dividedBy()` is now optional again.
696
697## [0.5.1](https://github.com/brick/math/releases/tag/0.5.1) - 2015-07-05
698
699**New method: `BigNumber::toScale()`**
700
701This allows to convert any `BigNumber` to a `BigDecimal` with a given scale, using rounding if necessary.
702
703## [0.5.0](https://github.com/brick/math/releases/tag/0.5.0) - 2015-07-04
704
705**New features**
706- Common `BigNumber` interface for all classes, with the following methods:
707 - `sign()` and derived methods (`isZero()`, `isPositive()`, ...)
708 - `compareTo()` and derived methods (`isEqualTo()`, `isGreaterThan()`, ...) that work across different `BigNumber` types
709 - `toBigInteger()`, `toBigDecimal()`, `toBigRational`() conversion methods
710 - `toInteger()` and `toFloat()` conversion methods to native types
711- Unified `of()` behaviour: every class now accepts any type of number, provided that it can be safely converted to the current type
712- New method: `BigDecimal::exactlyDividedBy()`; this method automatically computes the scale of the result, provided that the division yields a finite number of digits
713- New methods: `BigRational::quotient()` and `remainder()`
714- Fine-grained exceptions: `DivisionByZeroException`, `RoundingNecessaryException`, `NumberFormatException`
715- Factory methods `zero()`, `one()` and `ten()` available in all classes
716- Rounding mode reintroduced in `BigInteger::dividedBy()`
717
718This release also comes with many performance improvements.
719
720---
721
722**Breaking changes**
723- `BigInteger`:
724 - `getSign()` is renamed to `sign()`
725 - `toString()` is renamed to `toBase()`
726 - `BigInteger::dividedBy()` now throws an exception by default if the remainder is not zero; use `quotient()` to get the previous behaviour
727- `BigDecimal`:
728 - `getSign()` is renamed to `sign()`
729 - `getUnscaledValue()` is renamed to `unscaledValue()`
730 - `getScale()` is renamed to `scale()`
731 - `getIntegral()` is renamed to `integral()`
732 - `getFraction()` is renamed to `fraction()`
733 - `divideAndRemainder()` is renamed to `quotientAndRemainder()`
734 - `dividedBy()` now takes a **mandatory** `$scale` parameter **before** the rounding mode
735 - `toBigInteger()` does not accept a `$roundingMode` parameter anymore
736 - `toBigRational()` does not simplify the fraction anymore; explicitly add `->simplified()` to get the previous behaviour
737- `BigRational`:
738 - `getSign()` is renamed to `sign()`
739 - `getNumerator()` is renamed to `numerator()`
740 - `getDenominator()` is renamed to `denominator()`
741 - `of()` is renamed to `nd()`, while `parse()` is renamed to `of()`
742- Miscellaneous:
743 - `ArithmeticException` is moved to an `Exception\` sub-namespace
744 - `of()` factory methods now throw `NumberFormatException` instead of `InvalidArgumentException`
745
746## [0.4.3](https://github.com/brick/math/releases/tag/0.4.3) - 2016-03-31
747
748Backport of two bug fixes from the 0.5 branch:
749- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected
750- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
751
752## [0.4.2](https://github.com/brick/math/releases/tag/0.4.2) - 2015-06-16
753
754New method: `BigDecimal::stripTrailingZeros()`
755
756## [0.4.1](https://github.com/brick/math/releases/tag/0.4.1) - 2015-06-12
757
758Introducing a `BigRational` class, to perform calculations on fractions of any size.
759
760## [0.4.0](https://github.com/brick/math/releases/tag/0.4.0) - 2015-06-12
761
762Rounding modes have been removed from `BigInteger`, and are now a concept specific to `BigDecimal`.
763
764`BigInteger::dividedBy()` now always returns the quotient of the division.
765
766## [0.3.5](https://github.com/brick/math/releases/tag/0.3.5) - 2016-03-31
767
768Backport of two bug fixes from the 0.5 branch:
769
770- `BigInteger::parse()` did not always throw `InvalidArgumentException` as expected
771- Dividing by a negative power of 1 with the same scale as the dividend could trigger an incorrect optimization which resulted in a wrong result. See #6.
772
773## [0.3.4](https://github.com/brick/math/releases/tag/0.3.4) - 2015-06-11
774
775New methods:
776- `BigInteger::remainder()` returns the remainder of a division only
777- `BigInteger::gcd()` returns the greatest common divisor of two numbers
778
779## [0.3.3](https://github.com/brick/math/releases/tag/0.3.3) - 2015-06-07
780
781Fix `toString()` not handling negative numbers.
782
783## [0.3.2](https://github.com/brick/math/releases/tag/0.3.2) - 2015-06-07
784
785`BigInteger` and `BigDecimal` now have a `getSign()` method that returns:
786- `-1` if the number is negative
787- `0` if the number is zero
788- `1` if the number is positive
789
790## [0.3.1](https://github.com/brick/math/releases/tag/0.3.1) - 2015-06-05
791
792Minor performance improvements
793
794## [0.3.0](https://github.com/brick/math/releases/tag/0.3.0) - 2015-06-04
795
796The `$roundingMode` and `$scale` parameters have been swapped in `BigDecimal::dividedBy()`.
797
798## [0.2.2](https://github.com/brick/math/releases/tag/0.2.2) - 2015-06-04
799
800Stronger immutability guarantee for `BigInteger` and `BigDecimal`.
801
802So far, it would have been possible to break immutability of these classes by calling the `unserialize()` internal function. This release fixes that.
803
804## [0.2.1](https://github.com/brick/math/releases/tag/0.2.1) - 2015-06-02
805
806Added `BigDecimal::divideAndRemainder()`
807
808## [0.2.0](https://github.com/brick/math/releases/tag/0.2.0) - 2015-05-22
809
810- `min()` and `max()` do not accept an `array` anymore, but a variable number of parameters
811- **minimum PHP version is now 5.6**
812- continuous integration with PHP 7
813
814## [0.1.1](https://github.com/brick/math/releases/tag/0.1.1) - 2014-09-01
815
816- Added `BigInteger::power()`
817- Added HHVM support
818
819## [0.1.0](https://github.com/brick/math/releases/tag/0.1.0) - 2014-08-31
820
821First beta release.