-
Notifications
You must be signed in to change notification settings - Fork 28
The Big Refactor (formerly "Add BigReal interface") #32
Description
EDIT : This idea is no longer proposed, a new issue will be posted if we arrive to a consensus in this thread.
Because we want to introduce new classes for big numbers (See #15, #27, #28 and #29), it would be necessary to create a BigRealinterface or abstract class (more probably the second one) in order to allow interoperability between those classes.
Currently, the class Decimal have many defined methods, but almost all the methods use the$scale`parameter, which is very specific for this type. Because it's desirable to use type hinting in the methods signatures, and because PHP doesn't allow classical method overliading (as in Java or C#), I propose to do a big refactor with the following steps:
- rename the shareable methods from "method" to "dMethod" in the
Decimalclass (de ''d'' is for Decimal), wheremethodrefers to the previous method name, for examplemuloradd. - Add new methods with the old names, but without the
$scaleparameter, and hinting theBigNumbertype instead ofDecimal. Those methods should have a switch-like control structure to map the calls to the specific-type methods :dMethodforDecimalrMethodforBigRationaliMethodforBigIntegercMethodforBigComplexnMethodfor PHP's native types (see Add methods in Decimal to allow interaction with PHP's native numbers #16).
- Extract the new created methods to the new
BigRealabstract class, and makeDecimalto inherit fromBigReal.
Important Note: I'm talking about BigRealand not about BigNumber because this way we have more flexibility . Number is a very general concept, and may be in the future we want to implement other number types (not only real or complex numbers, but... say finite fields, quaternions or whatever you can imagine).