I was playing around with complex numbers and cmath on Python 3.9 when I tried printing the value for e^(i*pi). Here is my code for it:
import cmath print(cmath.exp(1.0j * cmath.pi)) print(cmath.cos(cmath.pi) + (1.0j)*cmath.sin(cmath.pi)) Both of these returned (-1+1.2246467991473532e-16j) but the imaginary part should not be there (though it is really small in magnitude).
Is there something I am missing in my code? Or is it something to do with cmath?
https://stackoverflow.com/questions/66513086/python-cmath-returns-wrong-value-for-eipi March 07, 2021 at 12:05PM
没有评论:
发表评论