bugGNU Octave - Bugs: bug #37455, tests do not distinguish -0

 
 

bug #37455: tests do not distinguish -0

Submitted by:  Michael Godfrey <godfrey>
Submitted on:  Fri 28 Sep 2012 02:22:40 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: InvalidAssigned to: None
Originator Name: Michael GodfreyOpen/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

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...)

Michael Godfrey <godfrey>
Project Member
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?

John W. Eaton <jwe>
Project Administrator
Sun 30 Sep 2012 03:51:57 PM UTC, comment #11:

The attached changeset clarifies that
sign(x) uses +- 0.

(file #26669)

Michael Godfrey <godfrey>
Project Member
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.

Michael Godfrey <godfrey>
Project Member
Sun 30 Sep 2012 01:51:25 AM UTC, comment #9:

What does Matlab do for the following?

?

John W. Eaton <jwe>
Project Administrator
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?

Michael Godfrey <godfrey>
Project Member
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.

Michael Godfrey <godfrey>
Project Member
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.

Michael Godfrey <godfrey>
Project Member
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.

Michael Godfrey <godfrey>
Project Member
Fri 28 Sep 2012 04:16:32 PM UTC, comment #4:

I suppose we could provide a copysign function for the interpreter.

John W. Eaton <jwe>
Project Administrator
Fri 28 Sep 2012 02:53:57 PM UTC, comment #3:

> But atan2, for example, distinguishes -0.


That is a separate problem. ;-)

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
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?

Michael Godfrey <godfrey>
Project Member
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)."

Jordi Gutiérrez Hermoso <jordigh>
Project Administrator
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?

Michael Godfrey <godfrey>
Project Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #26669:  sign_doc1.diff added by godfrey (906B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by jordigh (Posted a comment)
  • -unavailable- added by godfrey (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 30 Sep 2012 03:51:57 PM UTCgodfreyAttached File-=>Added sign_doc1.diff, #26669
    Fri 28 Sep 2012 02:49:23 PM UTCjordighStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1