-
Notifications
You must be signed in to change notification settings - Fork 84
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
Abnormal situation of converting "mpz" to "str" #489
Comments
Just now, I tried to use math.isort() instead gmpy2. I recalculated and the last few digits became "8778"... Even worse, when I I hate mathematics update: I found online that the number 1000000th is actually 1 |
The key issue in your code it the use of
|
Thank you for response. But when I run your code, the result is incorrect. I tried several times and eventually found that it lost accuracy when n >= 16383 (perhaps only on my computer). Also, interestingly, if only print(pi[-1]), it is correct(when n = 1000000). I think this goes far beyond my knowledge of programming. The purpose of this issue is only to remind you if there are any bugs in gmpy2. If I wrote the wrong code, you can close this issue. In fact, I have given up on continuing to delve into calculating pi or computer processing large numbers, which is too difficult. |
Closing. |
Hardware: Windows 10 PC (x86_64)
Python version: 3.12.1
gmpy2 version: 2.2.0
Problem: I am writing a program about calculating pi to n decimal places. It uses the Chudnovsky formula and binary splitting algorithm. Its calculation result is correct and the speed is very fast. Here is the code:
The calculated result is "31415......0995". I am sure it is correct because it is the same as the result before acceleration.
The problem is that when I try to take the last number, it does not match the expected result:
This is indeed confusing. So I started trying to debug:
So the length is correct, the type is correct, each character is correct, but it's just different, and slicing can also cause problems!
Is this a problem of CPython, gmpy2, or something else?...
The text was updated successfully, but these errors were encountered: