-
Notifications
You must be signed in to change notification settings - Fork 53
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
exp(x) or e^x uses large amounts of CPU and stalls on certain fractional values of x #289
Comments
That's caused by fend's use of arbitrary-precision rational numbers, whereas Rust just uses IEEE floats. You can see more details if you convert the result to a fraction, recurring decimal or use the
As a workaround, you can define your own less precise version of
Unfortunately if your exponent has a lot of decimal places it will still be extremely slow. Any PRs to improve performance would be more than welcome! I've also been considering adding a way to opt out of arbitrary-precision maths but this has also not been implemented. |
I think a way to specify precision would be very helpful. I will see if I can try to figure out a way to make that work, keep in mind I have never contributed to an open source project before. |
I've now merged in a performance improvement for exponentiation by decimal numbers, so calculations like |
e^27.2 at least now shows 5 more decimals then is accurate also e^0.2*e^27 shows 9 more then is accurate, don't know if you know that |
2^e takes alot of time also, it seems like you turn the number into a fraction but i can't find your fractions code to tell if it is fast or not, also 2^2.536543645276 should probably be computed as (2^(1/250000000000))^634135911319 instead of the big number first then the root. can't tell if that really matters for sure though. but probably is just best to use a taylors series to calculate this, i don't really see the benefit of what your doing |
Fractions are too slow for this kind of computations in general, so for this case arbitrary precision floating point numbers are used if precision is an issue, larger float type such as float-256 or regular old floats |
Reproduce:
> e^(27)
- Finishes immediately> e^(27.5)
- Finishes immediately> e^(27.2)
- Takes ~0.5s> e^(27.02)
- Stalls for a very long time, CPU usage jumps to 100% for a single core.This is what I was trying to calculate when I encountered this error:
FWIW, Rust handles this calculation just fine:
This program runs in under 2ms on my machine.
The text was updated successfully, but these errors were encountered: