python 使用 math.fmod() 得到奇怪的结果

标签 python modulus

我正在使用 Python 3.4 中的数学模块,在使用 fmod 函数时得到了一些奇怪的结果,但我很难从 python 网站获取详细信息。

一个简单的例子如下:

from math import *

x = 99809175801648148531
y = 6.5169020832937505
sqrt(x)-cos(x)**fmod(x, y)*log10(x)

它返回:

(9990454237.014296+8.722374238018135j)

如何解释这个结果? j是什么? 它是像 i 这样的虚数吗? 如果是这样,为什么是 j 而不是 i? 非常欢迎任何信息以及有关 fmod 的一些资源的链接。

最佳答案

您得到的结果是 complex number因为你对负数求幂了。 ij 只是表示 imaginary number unit 的符号选择。 ,i更多地用于数学,j更多地用于工程。您可以在文档中看到 Python 选择使用 j:

https://docs.python.org/2/library/cmath.html#conversions-to-and-from-polar-coordinates

关于python 使用 math.fmod() 得到奇怪的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27649738/

相关文章:

python - 将 PyArrow Parquet 加速到 Pandas 以获取具有大量字符串的数据帧

python - 金字塔在主包之外运行测试

python - 可替换多个可迭代对象或与订单无关的产品的高效组合

c++ - 如何在使用模数将十进制值转换为货币时使程序编译?

algorithm - 如何检查大十进制数是否可以除以 2^x 或 5^x

python - 如何在 AWS Lambda 中最好地使用 Python 3 的 mimetypes 模块?

python - numpy : What does this einsum expression mean and is there an alternative?

javascript - 在 javascript 中,如何在循环中有效地处理大数?

java - 简单的Java模数问题

powershell - 在Powershell中,生成距离间隔的最有效方法是什么?