Skip to content

Instantly share code, notes, and snippets.

@gvitalie
Last active November 24, 2025 06:37
Show Gist options
  • Select an option

  • Save gvitalie/81eca1264b9c5d93ed83061548a3b14b to your computer and use it in GitHub Desktop.

Select an option

Save gvitalie/81eca1264b9c5d93ed83061548a3b14b to your computer and use it in GitHub Desktop.
e^(jx) calculate exact π value.
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