math

Arbitrary-precision arithmetic library for PHP

MIT License

Downloads
306.3M
Stars
1.8K
Committers
13

Bot releases are visible (Hide)

math - 0.12.1 Latest Release

Published by BenMorel 11 months ago

⚡️ Performance improvements

  • BigNumber::of() is now faster, thanks to @SebastienDug in #77.
math - 0.12.0

Published by BenMorel 11 months ago

💥 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
math - 0.11.0

Published by BenMorel almost 2 years ago

💥 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.

math - 0.10.2

Published by BenMorel about 2 years ago

👌 Improvements

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

Published by BenMorel about 2 years ago

New features

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

Published by BenMorel over 2 years ago

💥 Breaking changes

  • Minimum PHP version is now 7.4
math - 0.9.3

Published by BenMorel about 3 years ago

🚀 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
math - 0.9.2

Published by BenMorel over 3 years ago

🐛 Bug fix

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

Published by BenMorel about 4 years ago

✨ 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
math - 0.8.17

Published by BenMorel about 4 years ago

🐛 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
math - 0.9.0

Published by BenMorel about 4 years ago

👌 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
math - 0.8.16

Published by BenMorel about 4 years ago

🚑 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()
math - 0.8.15

Published by BenMorel over 4 years ago

🐛 Fixes

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

⚡️ Optimizations

  • additional optimization in BigInteger::remainder()
math - 0.8.14

Published by BenMorel over 4 years ago

New features

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

Published by BenMorel over 4 years ago

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

Published by BenMorel over 4 years ago

🛠️ 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.

math - 0.8.11

Published by BenMorel over 4 years ago

New feature

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

math - 0.8.10

Published by BenMorel over 4 years ago

New feature

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

math - 0.8.9

Published by BenMorel almost 5 years ago

⚡️ 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.

math - 0.8.8

Published by BenMorel over 5 years ago

🐛 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