Dan*_*vil 7 c++ floating-point
在C++中,例如fmod(-2,2)返回-0.表达式-0 == 0是真的,但位不同.有什么样的东西-0应该0是以不同的方式表达的目的是什么?是-0使用完全相同的方式0在任何计算?
Giu*_*one 13
不,+0并且-0在每次计算中都不会以相同的方式使用.例如:
3·(+0) = +0
+0/-3 = -0
Run Code Online (Sandbox Code Playgroud)
I suggest you to read What Every Computer Scientist Should Know About Floating-point arithmetic by David Goldberg, that sheds a light on why +0 and -0 are needed in floating point arithmetic and in which way they differ.
Examples on how +0 ad -0 differ (and why that can be useful when dealing with complex values) can be found in Kahan, W. 1987. Branch Cuts for Complex Elementary Functions, in "The State of the Art in Numerical Analysis" (I wasn't able to find a pdf of this article, you may find one at your local university library).
Kor*_*icz 10
该符号零维基百科页面将回答大部分这些问题:
带符号的零为零,带有相关符号.在普通算术中,-0 = 0.然而,在计算中,一些数字表示允许存在两个零,通常用-0(负零)和+0(正零)表示.这发生在整数的一些有符号数表示中,并且在大多数浮点数表示中.数字0通常编码为+0,但它可以用+0或-0表示.
用于浮点运算的IEEE 754标准(目前大多数计算机和支持浮点数的编程语言使用)都需要+0和-0.零可以被认为是扩展实数线的变体,使得1/-0 =-∞和1/+ 0 = +∞,除以0仅对于±0 /±0未定义.
(......)
据称,在IEEE 754中包含有符号零点使得在一些关键问题中更容易实现数值精度,特别是在使用复杂的基本函数进行计算时.