Coder-Spirit / php-bignumbers

A robust library to handle immutable big numbers inside PHP applications
MIT License
131 stars 29 forks source link

Remove hardcoded dependency #64

Open Blackhol3 opened 6 years ago

Blackhol3 commented 6 years ago

It is currently impossible to work with trigonometric functions (cos(), sin(), …) with more than 32 digits of precision, since the calls to DecimalConstants, where pi() is limited to 32 digits, are hardcoded.

This PR allows to extend Decimal and to modify the value of Decimal::DECIMAL_CONSTANTS in order to change the class being called when numeric constants are needed.

castarco commented 6 years ago

I'll try to review this PR during this week. But my first diagonal reading gave me some simple insight that I want to share:

In addition to that... I'm not proud at all for the architecture of this library, and I think it need a better (& simpler replacement). This library tried to cover very different use cases (scientific computation, symbolic computation, & even financial computation), and that was a big mistake.

Blackhol3 commented 6 years ago

If you feel this PR is too big, the commits 66d636b and 3506a9c, although related, are rather independent and can be left aside at the moment.

About the architecture… Well, at least you're aware of the problem ^^. I've read somewhere that you care a lot about the performance of this library, so what I've proposed here is quite a hack, but it is probably the fastest way to go without reorganising the whole thing.

If you want some inspiration for the structure of this project, you can maybe check brick/math. I'm still hesitating between this two libraries, to be honest. Both have their advantages. Anyway, if you want some help for the refactoring, do not hesitate to share your thoughts. I'll be happy to give a hand!