views:

278

answers:

3

Hello,

This is an odd one I'm puzzled about. I recently noticed at the Gnu Octave prompt, it's possible to enter in negative zeroes, like so:

octave:2> abomination = -0

And it remembers it, too:

octave:3> abomination
abomination = -0

In the interest of sanity, negative zero does equal regular zero. But I also noticed that the sign has some other effects. Like these:

octave:6> 4 * 0
ans = 0
octave:7> 4 * -0
ans = -0
octave:8> 4 / 0
warning: division by zero
ans = Inf
octave:9> 4 / -0
warning: division by zero
ans = -Inf

As one can see, the sign is preserved through certain operations. But my question is why. This seems like a radical departure from standard mathematics, where zero is essentially without sign. Are there some attractive mathematical properties for having this? Does this matter in certain fields of mathematics?

FYI: Matlab, which octave is modeled after, does not have negative zeros. Any attempts to use them are treated as regular zeros.

EDIT: Matlab does have negative zeros, but they are not displayed in the default output.

+8  A: 
Joey
Yes, in some maths it's important to make a distinction between -Inf and +Inf such as the log(0)=-Inf
petantik
Well, infinities always have a sign. That wasn't my point anyway.
Joey
+5  A: 

Signed Zero

Signed zero echoes the mathematical analysis concept of approaching 0 from below as a one-sided limit, which may be denoted by x → 0−, x → 0−, or x → ↑0. The notation "−0" may be used informally to denote a negative number that has been rounded to zero. The concept of negative zero also has some theoretical applications in statistical mechanics and other disciplines.

nos
Hmm, not sure what can be done, but some formatting was lost in the notation part, so now the first two pieces look identical.
BigBeagle
+16  A: 

Signed zero are part of the IEEE-754 formats, and their semantics are completely specified by those formats. They turn out to be quite useful, especially when dealing with complex branch cuts and transformations of the complex plane (see many of W. Kahan's writings on the subject for more details, such as the classic "Branch Cuts for Complex Elementary Functions, or Much Ado about Nothing's Sign Bit").

Short version: negative zero is often a good thing to have in numerical calculations, and programs that try to protect users from encountering it are often doing them a disservice. FWIW, MATLAB does seem to use negative zero as well, but since it prints numbers using the host's printf routine, they display the same as positive zero on Windows.

See this discussion on the MATLAB forums for more details on signed zero in MATLAB.

Stephen Canon
Thanks for the Matlab catch. I added a note to the question.
BigBeagle