本文介绍了使用负零浮点值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下C ++代码:

Consider the following C++ code:

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

问题出现了:什么是负零有益的,

The question arises: what is negative zero good for, and should it be defensively avoided (i.e. use subtraction instead of smacking a minus onto a variable)?

推荐答案

从维基百科:

第一个引用是Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bitby W. Kahan,可供下载。

The first reference is "Branch Cuts for Complex Elementary Functions or Much Ado About Nothing's Sign Bit" by W. Kahan, that is available for download here.

该论文的一个示例是 1 /(+ 0) vs 1 /( - 0)。这里,零的符号有很大的差别,因为第一个表达式等于 + inf ,第二个表达式 -inf

One example from that paper is 1/(+0) vs 1/(-0). Here, the sign of zero makes a huge difference, since the first expression equals +inf and the second, -inf.

这篇关于使用负零浮点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 04:18
查看更多