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 BigReal
interface 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
Decimal
class (de ''d'' is for Decimal), wheremethod
refers to the previous method name, for examplemul
oradd
. - Add new methods with the old names, but without the
$scale
parameter, and hinting theBigNumber
type instead ofDecimal
. Those methods should have a switch-like control structure to map the calls to the specific-type methods :dMethod
forDecimal
rMethod
forBigRational
iMethod
forBigInteger
cMethod
forBigComplex
nMethod
for 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
BigReal
abstract class, and makeDecimal
to inherit fromBigReal
.
Important Note: I'm talking about BigReal
and 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).