Campbell Ritchie

Sheriff

Posts: 53561

126

posted 1 month ago

- 1

The mathematicians will tell you that there is no such thing as -0. But computer arithmetic does not usually follow strict mathematical notions. It follows IEEE754 for floating‑point numbers. Look it up on Wikipedia or elsewhere. It mandates negative 0 and also that there is no difference between that and ordinary 0.

Note that does not apply strictly to the wrapper classes:-Yes, I know d0 and d_0 are bad names for variables.

Note that does not apply strictly to the wrapper classes:-Yes, I know d0 and d_0 are bad names for variables.

Campbell Ritchie

Sheriff

Posts: 53561

126

Stephan van Hulst

Saloon Keeper

Posts: 6841

100

posted 1 month ago

They are equivalent, but not identical. The difference becomes clear when you divide something by zero and negative zero:

*The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.*

posted 1 month ago

Thanks Campbell for your nice post.

This post raised me other questions.

:-)

Campbell Ritchie wrote:The mathematicians will tell you that there is no such thing as -0. But computer arithmetic does not usually follow strict mathematical notions. It follows IEEE754 for floating‑point numbers. Look it up on Wikipedia or elsewhere. It mandates negative 0 and also that there is no difference between that and ordinary 0.

Note that does not apply strictly to the wrapper classes:-Yes, I know d0 and d_0 are bad names for variables.

Thanks Campbell for your nice post.

This post raised me other questions.

:-)

OCAJP 7

It is sorta covered in the JavaRanch Style Guide. |