Uses for negative zero floating point value?

前端 未结 5 1368
天命终不由人
天命终不由人 2020-12-03 04:53

Consider the following C++ code:

double someZero = 0;
std::cout << 0 - someZero << \'\\n\';   // prints 0
std::cout << -someZero << s         


        
5条回答
  •  隐瞒了意图╮
    2020-12-03 05:54

    Negative zero has for example some use when handling complex numbers...

    In everyday use one should mostly avoid the negative zero.

    Some links with information regarding background/uses/pitfalls of "negative zero":

    • http://en.wikipedia.org/wiki/Signed_zero
    • http://en.wikipedia.org/wiki/Floating_point#Signed_zero
    • http://en.wikipedia.org/wiki/Branch_cut
    • http://connect.microsoft.com/VisualStudio/feedback/details/344366/negative-zero-behavior-between-c-and-c-code-is-different
    • http://connect.microsoft.com/VisualStudio/feedback/details/292276/in-vs2005-c-zero-reported-as-negative-zero-for-double-type
    • C++ ceil and negative zero

提交回复
热议问题