Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

The Big Refactor (formerly "Add BigReal interface") #32

Open
@castarco

Description

@castarco

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 Decimal class (de ''d'' is for Decimal), where method refers to the previous method name, for example mul or add.
  • Add new methods with the old names, but without the $scaleparameter, and hinting the BigNumbertype instead of Decimal. Those methods should have a switch-like control structure to map the calls to the specific-type methods :
  • Extract the new created methods to the new BigRealabstract class, and make Decimalto inherit from BigReal.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions