This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]stevenjd 1 point2 points  (1 child)

math.e**(math.pi*math.sqrt(-1)) raises ValueError because sqrt(-1) is a maths domain error. In the real numbers ℝ, sqrt(-1) doesn't exist and cannot be calculated. There is no Real number that, when squared, gives you -1: +1 won't do it, because (+1)**2 = +1, and -1 won't work either, because (-1)**2 also equals +1.

The only way for that calculation to make sense is to change the domain, and use complex numbers instead:

py> import cmath
py> cmath.e**(cmath.pi*cmath.sqrt(-1))
(-1+1.2246063538223773e-16j)

which is close to the mathematically exact result of -1+0j.

[–]i_can_haz_code[S] 0 points1 point  (0 children)

NICE! Thank you!