[英]Why does double.Parse ignore the sign of zero?
For example, in: 例如,在:
bool eq = (1 / double.Parse("-0.0")) == (1 / -0.0);
eq
will be false
. eq
将是false
。
double.Parse
would have to go through some trouble to explicitly ignore the sign for zero, even though not doing that almost never results in a problem. double.Parse
必须经历一些麻烦才能明确地将符号忽略为零,即使不这样做也几乎不会导致问题。 Since I need the raw representation, I had to write my own parsing function which special-cases negative zero and uses double.Parse
for everything else. 因为我需要原始表示,所以我必须编写自己的解析函数,特殊情况为负零,并使用
double.Parse
进行其他操作。
That's not a big problem, but I'm really wondering why they made the decision to ignore the sign of zero, because it seems to me that not doing so wouldn't be a bad thing. 这不是一个大问题,但我真的很想知道为什么他们决定忽略零的标志,因为在我看来,不这样做不会是坏事。
我不知道该干嘛本身,而是一个潜在的解决方案:如果你看到一个-
开头的性格,解析字符串的其余部分,然后否定它。
There is the difference: 有区别:
double.Parse("-0.0") = 0, 1/0 -> INF double.Parse(“ - 0.0”)= 0,1 / 0 - > INF
1/-0.0 -> -INF 1 / -0.0 - > -INF
But the minus operator in statement 2 doesn't mean "-0.0". 但是语句2中的减号运算符并不意味着“-0.0”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.