小编Bla*_*ker的帖子

Python 3输出奇怪的算术结果

我正在用Python编写计算器,并正在处理求幂.在处理小数的指数时,我遇到了一些非常奇怪的东西,所以我尝试在控制台中重现问题.这就是我得到的:

Python 3.5.2 (default, Oct 11 2016, 04:59:56) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> num1 = -3.0
>>> num2 = 2.5
>>> opr = '^'
>>> if opr == '^':
...     print(num1**num2)
... 
(4.772588574262081e-15+15.588457268119896j)
>>> -3.0**2.5
-15.588457268119896
Run Code Online (Sandbox Code Playgroud)

有关如何避免第一个输出并获得第二个输出的任何指针?我不完全确定第一个输出甚至代表什么.

python math

3
推荐指数
2
解决办法
116
查看次数

标签 统计

math ×1

python ×1