My program seems to be producing some -0 values in place of values that should be 0. How do i stop my program from outputting these values?
Is it as simple as checking if a value is equal to -0 and reassigning it a zero instead? Or is there a more elegant solution?
Since a tag says visual-c++, it seems you’re running on Windows on an Intel or compatible chip, so integer values of -0 aren’t possible. Maybe you have a floating point value that’s negative but very close to 0, for example -0.000000000000009, and maybe you’re printing it with only a few digits of precision, for example -0.00000. In this case you could do something like:
Of course you want to do it with more style than that, but that gives you an idea.
The main text of your question doesn’t say Visual C++ or Windows or Intel. If you’re running on a one’s complement machine, integer values of -0 are possible. Normally -0 compares equal to +0, so the following code would normalize integer zeros: