Python:复数的较高精度-math.e **(pi * 1j)

问题描述 投票:0回答:1

我的Eulers身份代码提供了这种精度:

math.e**(pi*1j)
>> (-1+1.22464679915e-16j)

有没有一种方法可以“调整” Xe-30的精度?例如,有没有办法舍入到最接近的Xe-10?

我尝试了mpf(math.e **(pi * 1j))指定mp.prec = 30->这给我一个错误,可能是因为复数无法转换为浮点数。 (“无法从-1 + 1.22 ... e-16j创建mpg”)

在此先感谢所有乐于助人的人!

python precision complex-numbers e
1个回答
0
投票

您可以尝试这样做:

from decimal import *

getcontext().prec = 100#Number of decimal places
answer = Decimal(1) / Decimal(7)#1 and 7 are just examples, you could put any number in
print(answer)
© www.soinside.com 2019 - 2024. All rights reserved.