Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorial function? #50

Open
joeyhub opened this issue Sep 17, 2020 · 4 comments
Open

Factorial function? #50

joeyhub opened this issue Sep 17, 2020 · 4 comments

Comments

@joeyhub
Copy link

joeyhub commented Sep 17, 2020

For the sake of performance it would be great to have a factorial function in the library. It's in the documentation but as a PHP implementation.

I use gmp for it at the moment. I'm not sure if it's linear or not but either way C will be much faster for very large numbers.

On another note, this library is able to compute pow much faster than bcmath for very large exponents. This library can calculate something that ends up at E-500000 very quickly but bcmath takes prohibitively long.

I would recommend it to people having problems with bcmath and bcpow.

Another thing that bothers me is why so many of this libraries don't support initialisation from native php float which is a bit mind boggling. I have to use number_format($n, 72, '.', '').

@joeyhub
Copy link
Author

joeyhub commented Sep 17, 2020

It would also be very useful to have a documented way of formally suppressing the precision loss error and perhaps instead formally being able to check for it and taking the action of choice.

@rtheunissen
Copy link
Contributor

Another thing that bothers me is why so many of this libraries don't support initialisation from native php float which is a bit mind boggling.

I think that these libraries opt to not be responsible for how to treat floating point values, instead leaving that up to the user or language itself. For example, casting a float to a string in PHP itself (string) $f is likely more consistent and predictable based on the language's configuration, eg .ini precision.

In saying that, it does introduce the potential for non-deterministic behavior. I'll take a look at introducing a format "from float" mechanism in 2.0 which I'm working on a stable release for, hopefully today.

@rtheunissen
Copy link
Contributor

It would also be very useful to have a documented way of formally suppressing the precision loss error and perhaps instead formally being able to check for it and taking the action of choice.

I'll take a look at this too. 👍

@rtheunissen
Copy link
Contributor

For the sake of performance it would be great to have a factorial function in the library. It's in the documentation but as a PHP implementation.

mpdecimal does not have a factorial function built in but we can definitely support a formal version of it that calculates it using basic iterative multiplication. Adding to the list. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants