Thu 04 Oct 2012 03:59:31 PM UTC, comment #13:
This is great, subject to implementation of signbit()!!
(See my message trying to convince Jordi that it is
worth doing...)
|
Thu 04 Oct 2012 02:23:32 PM UTC, comment #12:
Michael, instead of your patch for the sign docstring, I checked in the following change:
http://hg.savannah.gnu.org/hgweb/octave/rev/481417a57a2d
I thought this behavior deserved a little more explanation. OK?
|
Sun 30 Sep 2012 03:51:57 PM UTC, comment #11:
The attached changeset clarifies that
sign(x) uses +- 0.
(file #26669)
|
Sun 30 Sep 2012 02:42:59 AM UTC, comment #10:
John,
>> x = -0
x =
0
>> 1/x
ans =
-Inf
>> x = 1/-Inf
x =
0
>> 1/x
ans =
-Inf
>>
>> version
ans =
7.9.0.529 (R2009b)
>>
So, it knows about -0, but does not show it!
y =0;
1/y
gives Inf, of course.
|
Sun 30 Sep 2012 01:51:25 AM UTC, comment #9:
What does Matlab do for the following?
?
|
Sun 30 Sep 2012 12:46:51 AM UTC, comment #8:
After some more study, it seems to me that implementing
signbit as in C++ is the best choice. copybit could
also be implemented at the same time, but seems much less
important. It appears that signbit could go in lo-mappers.cc
without much trouble.
An alternative would be to modify the current sign
so that sign(-0) returns -1 instead of 0. This would not
be incompatible with Matlab since it does not use -0, but
might be confusing.
Comments?
|
Fri 28 Sep 2012 07:04:12 PM UTC, comment #7:
I should have posted the comment below to
bug #37379. Will do that soon.
|
Fri 28 Sep 2012 06:52:41 PM UTC, comment #6:
I am still in favor of implementing signbit(), but
I think that the atan2 problem could be dealt with by:
function res = atan2(y, x)
% Test for special cases and quadrants.
if(x == 0)
if(y > 0)
res = pi/2;
elseif (y < 0)
res = -pi/2;
else
res = NaN;
endif
return;
endif
res = atan(y/x);
if(x < 0)
if(y >= 0)
res = res + pi;
else
res = res - pi;
endif
endif
return;
endfunction
This does need further checking, but it appears
to work, and make aten2 more consistent with the
other trig functions with respect to complex values.
|
Fri 28 Sep 2012 05:09:45 PM UTC, comment #5:
How about implementing the libm (ISO/IEC)
signbit macro?
It returns != 0 for -0. Just what we need.
|
Fri 28 Sep 2012 04:16:32 PM UTC, comment #4:
I suppose we could provide a copysign function for the interpreter.
|
Fri 28 Sep 2012 02:53:57 PM UTC, comment #3:
> But atan2, for example, distinguishes -0.
That is a separate problem. ;-)
|
Fri 28 Sep 2012 02:53:04 PM UTC, comment #2:
OK. But atan2, for example, distinguishes -0.
And 1/0 yields Inf, but 1/-0 yields -Inf.
Currently, this is the only way I have found to
determine -0. Is there a better way?
|
Fri 28 Sep 2012 02:49:23 PM UTC, comment #1:
No, no, zero is equal to itself regardless of sign. See IEEE 754 section 5.11: "Comparisons shall ignore the sign of zero (so +0 = −0)."
|
Fri 28 Sep 2012 02:22:40 PM UTC, original submission:
(-0 == 0) returns true. Since -0 and 0 are distinguished it
would seem appropriate for -0 == 0 to return false.
Is there objection to making this change?
|