Why do doubles have -0 as well as +0? What is the background and significance?
Why do doubles have -0 as well as +0 ? What is the background
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
-0is (generally) treated as0*******. It can result when a negative floating-point number is so close to zero that it can be considered0(to be clear, I’m referring to arithmetic underflow, and the results of the following computations are interpreted as being exactly±0, not just really small numbers). e.g.If we consider the same case with a positive number, we will receive our good old
0:******* Here’s a case where using
-0.0results in something different than when using0.0:This makes sense if we consider the function
1 / x. Asxapproaches0from the+-side, we should get positive infinity, but as it approaches from the--side, we should get negative infinity. The graph of the function should make this clear:(source)
In math-terms:
This illustrates one significant difference between
0and-0in the computational sense.Here are some relevant resources, some of which have been brought up already. I’ve included them for the sake of completeness: