Benjamin Morel
c1bdb3b9b5
Add BigNumber::toScale()
...
This allows to convert any BigNumber to a BigDecimal of the given scale.
2015-07-05 13:07:10 +02:00
Benjamin Morel
aa43c637b7
Re-introduce rounding mode in BigInteger::dividedBy()
2015-07-04 01:35:02 +02:00
Benjamin Morel
38a6b8c342
Add BigNumber::toInteger() and toFloat() methods
...
These methods are implemented by BigInteger, BigDecimal and BigRational.
- toInteger() returns an exact value or throws an exception
- toFloat() returns an approximate value
2015-07-03 17:22:43 +02:00
Benjamin Morel
45e3c3a463
Remove get prefix in method names
...
This improves overall consistency of method names in the project.
For example, it does not make sense to get the reciprocal of a BigRational using reciprocal(), but get its numerator using getNumerator().
List of renamed methods:
- BigNumber::getSign() => sign()
- BigDecimal::getUnscaledValue() => unscaledValue()
- BigDecimal::getScale() => scale()
- BigDecimal::getIntegral() => integral()
- BigDecimal::getFraction() => fraction()
- BigRational::getNumerator() => numerator()
- BigRational::getDenominator() => denominator()
2015-07-03 16:17:23 +02:00
Benjamin Morel
da27465258
Refactor tests
2015-07-03 16:03:58 +02:00
Benjamin Morel
97c7c45c51
All BigNumber subclasses now have zero(), one() and ten() factory methods
...
These methods are optimized for re-usability, and other methods now internally use them.
2015-07-03 15:36:57 +02:00
Benjamin Morel
7eeb9d3ca0
Parameters to BigNumber methods must be convertible to the current type
...
This applies to plus(), minus(), multipliedBy(), dividedBy().
2015-06-28 01:40:03 +02:00
Benjamin Morel
d0a91c6be1
Add missing BigInteger tests
2015-06-26 13:41:47 +02:00
Benjamin Morel
1b8b3e43bb
Add basic arithmetic operations to BigNumber
...
- BigInteger::dividedBy() previous implementation is now quotient()
- BigDecimal::dividedBy() previous implementation is now dividedByWithRounding()
2015-06-26 00:36:19 +02:00
Benjamin Morel
eae8ddc49f
Move min() and max() implementations to BigNumber
2015-06-23 13:24:12 +02:00
Benjamin Morel
77610f5fdc
Proper comparison of every BigNumber against all rational number formats
2015-06-22 22:42:10 +02:00
Benjamin Morel
27bc623b70
BigNumber::of() now throws NumberFormatException instead of InvalidArgumentException
...
This allows to catch all of() exceptions with the parent, ArithmeticException.
2015-06-22 22:13:19 +02:00
Benjamin Morel
d6aa1007a9
Introducing a specific RoundingNecessaryException
2015-06-22 21:53:32 +02:00
Benjamin Morel
ed8e1075e2
Introducing a specific DivisionByZeroException
2015-06-22 14:12:40 +02:00
Benjamin Morel
7680dcf634
Move ArithmeticException to an Exception sub-namespace
2015-06-22 13:57:47 +02:00
Benjamin Morel
c343e0aeb9
Merge of() factory methods in BigNumber
2015-06-22 12:50:44 +02:00
Benjamin Morel
321c00281d
CS fixes
...
Shorthand "int" and "bool" are now used instead of "integer" and "boolean".
This makes more sense as the latter are not accepted as synonyms in PHP 7 scalar type hints and return types.
2015-06-21 14:37:51 +02:00
Benjamin Morel
12bea2c474
BigInteger::toString() is now toBase()
2015-06-21 14:21:28 +02:00
Benjamin Morel
cc30889769
BigInteger::dividedBy() now always returns the quotient
...
Rounding is a concept left to BigDecimal only from now on.
2015-06-12 10:25:00 +00:00
Benjamin Morel
115455238b
Clean up unused imports
2015-06-12 01:20:44 +02:00
Benjamin Morel
4f4b9531ed
Add BigInteger::gcd()
...
This computes the greatest common divisor of two large integers.
2015-06-11 23:35:47 +02:00
Benjamin Morel
1f577afe11
Add BigInteger::remainder() method
...
This allows to return the remainder of the division only.
2015-06-11 22:31:07 +02:00
Benjamin Morel
2c35d6fc5b
Fix negative numbers not supported by toString()
2015-06-08 00:12:50 +02:00
Benjamin Morel
e9da17c78d
Add getSign() method to BigInteger and BigDecimal
2015-06-07 14:48:49 +02:00
Benjamin Morel
536e6414e6
Performance optimizations
2015-06-05 22:17:20 +02:00
Benjamin Morel
908e73e8e4
unserialize() now throws an exception when called directly
...
This guarantees that immutability cannot be broken.
2015-06-04 12:14:42 +02:00
Benjamin Morel
9ab6358fc2
min() and max() now use variadics
2015-05-22 13:19:08 +02:00
Benjamin Morel
4d18be75e1
Tests now run a single calculator instance at a time
2015-01-27 17:38:31 +01:00
Benjamin Morel
61968fcee9
Added BigInteger::power()
2014-09-01 19:10:04 +02:00
Benjamin Morel
2b8ebcd55e
Changed tests namespace to Brick\Math\Tests
2014-08-31 14:24:10 +02:00
Benjamin Morel
5dfd5c45d0
Import from the incubator
2014-08-31 12:13:46 +00:00