Benjamin Morel
db16e619c3
Add BigDecimal::quotient() and remainder() methods
2015-07-03 18:05:02 +02:00
Benjamin Morel
271b619453
Rename BigDecimal::dividedAndRemainder() to quotientAndRemainder()
...
This is consistent with the naming of the BigInteger method.
2015-07-03 17:54: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
751ba3592f
Clean up unused import
2015-07-03 16:03:46 +02:00
Benjamin Morel
f2e4ac3f90
Fix wrongly documented return value
2015-07-03 15:52:24 +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
2130b893c2
Split Calculator::div() into divQ(), divR() & divQR()
...
This will result in a slight performance improvement.
2015-07-03 14:12:46 +02:00
Benjamin Morel
5fe1176af9
BigDecimal::toBigRational() does not simplify the fraction any more
2015-07-03 13:46:48 +02:00
Benjamin Morel
050329ca23
Add quotient and remainder methods to BigRational
2015-07-03 13:32:13 +02:00
Benjamin Morel
10a4d13ea3
Better doc for basic arithmetic functions, of() in each subclass
2015-07-03 13:24:33 +02:00
Benjamin Morel
9418e2a337
Add BigDecimal::of() tests for float values INF and NAN
2015-06-30 13:45:51 +02:00
Benjamin Morel
9cd19d460b
Fix typo in docblock
2015-06-28 23:40:14 +02:00
Benjamin Morel
1420202440
Exact division algorithm is now in BigDecimal::dividedBy()
...
BigRational::toBigDecimal() is now really just a proxy method to BigDecimal::dividedBy().
2015-06-28 22:51:02 +02:00
Benjamin Morel
5ccc6641b5
Fix typos
2015-06-28 19:29:25 +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
b3371daab2
BigDecimal::dividedByWithRounding() is now dividedToScale()
...
The $scale and $roundingMode parameters have been swapped.
2015-06-27 11:51:28 +02:00
Benjamin Morel
831d604169
Performance improvement on type conversions
...
Constructors of all BigNumber sub-classes are now accessible to each other via a proxy method in the parent class.
2015-06-27 01:18:32 +02:00
Benjamin Morel
7376e828c2
Remove BigDecimal::dividedByExact(), now implemented by dividedBy()
2015-06-26 23:47:44 +02:00
Benjamin Morel
d0a91c6be1
Add missing BigInteger tests
2015-06-26 13:41:47 +02:00
Benjamin Morel
baba83c721
Remove dead code Calculator::sign()
2015-06-26 13:28:24 +02:00
Benjamin Morel
5f42e8c4d7
All calculators now use the string-based cmp() implementation
...
This proved to be faster even when using GMP and BCMath.
2015-06-26 12:57:11 +02:00
Benjamin Morel
9ac821c06e
Speed up GCD calculation with GMP
2015-06-26 00:57:22 +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
17ac6de002
Docblock improvements
2015-06-23 12:46:36 +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
1ade407e23
Remove BigRational::get(), redundant with of()
2015-06-22 22:29:30 +02:00
Benjamin Morel
89a43d49a6
Precision about rational numbers
2015-06-22 22:15:02 +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
8b2d6781cd
BigInteger, BigDecimal and BigRational are now final
2015-06-22 12:51:21 +02:00
Benjamin Morel
c343e0aeb9
Merge of() factory methods in BigNumber
2015-06-22 12:50:44 +02:00
Benjamin Morel
d047282ec9
Disable PHPUnit globals backup
...
This is not useful for this test suite, and uselessly affects performance.
2015-06-22 12:41:35 +02:00
Benjamin Morel
41c34b1014
Add tests for BigDecimal::of() with leading zeros in exponent
2015-06-21 15:13:54 +02:00
Benjamin Morel
65d4dd75d6
Rename BigRational factory methods
...
- `BigRational::parse()` is now `of()`
- `BigRational::of()` is now `nd()`
This keeps BigRational in line with BigInteger and BigDecimal, whose `of()` factory method accepts a single parameter.
The new way to create a BigRational from two numbers is now called `nd()` for numerator/denominator.
2015-06-21 14:48:26 +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
3fd07960ef
Fix parse() method on latest PHP 7
...
The behaviour of substr() has been changed following the fix of this bug:
https://bugs.php.net/bug.php?id=62922
By this commit:
257054e81d
2015-06-21 14:14:34 +02:00
Benjamin Morel
3afa5cef7b
Simplification of NativeCalculator::init()
2015-06-21 14:01:44 +02:00
Benjamin Morel
1c7902cd48
Fix NativeCalculator::cmp() implementation
...
This was returning negative numbers other than -1 and positive numbers other than 1.
2015-06-21 13:55:44 +02:00
Benjamin Morel
32e898a3c2
Add release process notes
...
[ci skip]
2015-06-20 23:54:06 +02:00
Benjamin Morel
f3e4b2032c
Faster cmp() implementation for NativeCalculator
2015-06-20 22:59:39 +02:00
Benjamin Morel
20030b6798
Fix documentation referring to Decimal instead of BigDecimal
2015-06-20 13:45:47 +02:00
Benjamin Morel
c1aa379479
BigNumber is now an abstract class
...
This allows the factorization of most comparison & sign functions in a single place.
Only `compareTo()` and `getSign()` are now abstract, the others methods are based on these two.
2015-06-20 13:37:10 +02:00
Benjamin Morel
5d65ef08cc
Comparison and sign methods are now part of the BigNumber interface
2015-06-20 13:25:55 +02:00
Benjamin Morel
2619c02fd6
Add __toString() to the BigNumber interface
2015-06-20 11:01:46 +02:00