Background
Floating point numbers have one bit that is used to designate sign, and this bit applies when the value of the number is zero. This is called "
signed zero". MATLAB hides this very well in most situations, but it does pop up in certain cases. Recently this came up in a question on Stack Overflow involving complex numbers initialization.
Example
Below is a demonstration of how one complex number initialization syntax can inadvertently create a signed zero.
Create two complex numbers,
a and
b. The intent it that both variables have the value (0, -1).
>> a = 0-j;
>> b = -j;
Extract the real component and verify that they are
0, and that they are "equal".
>> ra = real(a)
ra =
0
>> rb = real(b)
rb =
0
>> ra==0
ans =
1
>> isequal(ra,rb)
ans =
1
But it's clear they are not equal with this operation:
>> 1/ra
ans =
Inf
>> 1/rb
ans =
-Inf
Interesting. Why does
rb clearly have a sign associated with it even though it is not visisble?