Floating point numbers (according to the standard1 nearly all programming languages use) are stored with a certain number of bits in the mantissa, in the exponent, and with a sign bit. As such, floating point numbers can make a difference between zero and minus zero. In almost all applications, that doesn't make a difference. For example, on the Python prompt, you get
>>> 0.0
0.0
>>> -1*0.0
-0.0
>>> -1*0.0 == 0.0
True
so the two compare equal.
Why are numbers not normalized so that there is only one zero? Because sometimes you want to know whether a number may have been obtained by underflow. For example:
>>> 1e-300/1e300
0.0
>>> -1e-300/1e300
-0.0
(This is because there are only so many bits in the exponent, and the smallest by magnitude number that can be stored is approximately 1e-308
, so the result of the computations above is rounded down to zero.)
Of course, a completely different possibility is that you really have numbers different from zero but very small and that for whatever reason you have set up your system in such a way that everything that is smaller than a certain value is printed as zero. In those cases, even if variables a
and b
are shown as zero (possibly with a sign), they are not in fact zero and consequently don't compare equal.
1 For your information and further research, the standard is IEEE 754.