原始浮点值如何为-0.0?那是什么意思? [英] How can a primitive float value be -0.0? What does that mean?
问题描述
我可以取消这个功能吗?
当我有:
float fl;
然后 fl == -0.0
code> true ,所以 fl == 0
。但是,当我打印它时,它打印 -0.0
。
Java使用浮点运算IEEE标准(IEEE 754),它定义了 -0.0
以及何时应该使用。
$ b
最小数字表示没有1位低于正常的有效数,被称为正数或负数零符号。它实际上是表示在0和同一符号的最小可表示的非零数字之间的范围内舍入到零的数字,这就是为什么它有一个符号,为什么它的倒数+ Inf或 - Inf还有一个标志。
你可以通过添加 0.0 $ c $例如
Double.toString(value + 0.0) ;
请参阅: 涉及负零的操作 > - - 0.0是在浮点运算产生一个如此接近0的负浮点数而不能产生正常表示。 How come a primitive float value can be -0.0? What does that mean? When I have: Then Because Java uses the IEEE Standard for Floating-Point Arithmetic (IEEE 754) which defines The smallest number representable has no 1 bit in the subnormal significand and is called the positive or negative zero as determined by the sign. It actually represents a rounding to zero of numbers in the range between zero and the smallest representable non-zero number of the same sign, which is why it has a sign, and why its reciprocal +Inf or -Inf also has a sign. You can get around your specific problem by adding e.g. See: Java Floating-Point Number Intricacies Operations Involving Negative Zero - "-0.0" is produced when a floating-point operation results in a negative floating-point number so close to 0 that cannot be represented normally.
这篇关于原始浮点值如何为-0.0?那是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
...
(-0.0)+ 0.0 - > 0.0
$ b
Can I cancel that feature? float fl;
fl == -0.0
returns true
and so does fl == 0
. But when I print it, it prints -0.0
.-0.0
and when it should be used.
0.0
Double.toString(value + 0.0);
...
(-0.0) + 0.0 -> 0.0