python - 乘法结果为负零

标签 python

有人能告诉我为什么下面提到的代码的输出是负零吗??

a * b = -0

这里'a'是long类型,b是decimal类的对象.....如果a=-28和b=0,那么输出是-0

最佳答案

来自 Python decimal文档:

The signed zeros can result from calculations that underflow. They keep the sign that would have resulted if the calculation had been carried out to greater precision. Since their magnitude is zero, both positive and negative zeros are treated as equal and their sign is informational.

关于python - 乘法结果为负零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5131428/

相关文章:

Python:在多种条件下查找数组的索引

python - 高效使用python的lambda、map

python - pandas:使用 loc 迭代 DataFrame 索引

python - 无法解决 Flask 设置中的 mod_wsgi 异常

python - 如何在 Pandas 中添加 "order within group"列?

python - 字典中的关系元组列表

python - 如何在python中将集合转换为列表?

使用类型作为函数参数的 Pythonic 方式

python - 如果第二个元素不是重复的,则删除二维 numpy 数组的行

javascript - 性能如果(typeof x == 'number')?