开发者

multiplication result is negative zero

开发者 https://www.devze.com 2023-02-13 21:54 出处:网络
can someone tell me why the output of the code mentioned below is negative zero?? a* b= -0 here \'a\' is of type long,b is an object of decimal开发者_开发问答 class.....and if a=-28 and b=0, then th

can someone tell me why the output of the code mentioned below is negative zero??

a * b = -0

here 'a' is of type long, b is an object of decimal开发者_开发问答 class.....and if a=-28 and b=0, then the output is -0


From the Python decimal docs:

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.


This explains it all :

http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm

it's something very close to zero, but on the minus side, that is why this happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消