math

Arbitrary-precision arithmetic library for PHP

MIT License

Downloads
306.3M
Stars
1.8K
Committers
13

Bot releases are hidden (Show)

math - 0.8.7

Published by BenMorel over 5 years ago

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.

math - 0.8.6

Published by BenMorel over 5 years ago

New method

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

math - 0.8.5

Published by BenMorel over 5 years ago

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 👍

math - 0.8.4

Published by BenMorel almost 6 years ago

New method

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

math - 0.8.3

Published by BenMorel almost 6 years ago

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.

math - 0.8.2

Published by BenMorel almost 6 years ago

Performance update

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

Published by BenMorel almost 6 years ago

Performance optimization of toInt() methods.

math - 0.8.0

Published by BenMorel about 6 years ago

Breaking changes

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

Method removed Replacement method
BigDecimal::getIntegral() BigDecimal::getIntegralPart()
BigDecimal::getFraction() BigDecimal::getFractionalPart()

New features

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

New method Description
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 👍

math - 0.7.3

Published by BenMorel about 6 years ago

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
math - 0.7.2

Published by BenMorel about 6 years ago

Performance update

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

math - 0.7.1

Published by BenMorel over 6 years ago

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.

math - 0.7.0

Published by BenMorel about 7 years ago

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
math - 0.6.2

Published by BenMorel about 7 years ago

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

math - 0.6.1

Published by BenMorel about 7 years ago

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.

math - 0.6.0

Published by BenMorel about 7 years ago

  • 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()
math - 0.5.4

Published by BenMorel about 8 years ago

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

math - 0.3.5

Published by BenMorel over 8 years ago

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.
math - 0.4.3

Published by BenMorel over 8 years ago

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.
math - 0.5.3

Published by BenMorel over 8 years ago

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.

math - 0.5.2

Published by BenMorel about 9 years ago

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