-
-
Save gvitalie/81eca1264b9c5d93ed83061548a3b14b to your computer and use it in GitHub Desktop.
e^(jx) calculate exact π value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| me@amadeus:~$ python3 -q | |
| >>> def exp(x): | |
| ... prod = a = 1 | |
| ... for i in range(1, 30): | |
| ... prod *= x/i | |
| ... a += prod | |
| ... return a | |
| ... | |
| >>> x = 1.5 | |
| >>> for i in range(3): | |
| ... x += exp(x * 1j).real | |
| ... | |
| >>> 2 * x | |
| 3.1415926535897936 | |
| >>> | |
| >>> x = 3 | |
| >>> for i in range(3): | |
| ... x += exp(x * 1j).imag | |
| ... | |
| >>> x | |
| 3.141592653589793 | |
| >>> | |
| me@amadeus:~$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment