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

 
 

bug #37455: tests do not distinguish -0

Submitter:  Michael Godfrey <godfrey>
Submitted:  Fri 28 Sep 2012 02:22:40 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Michael Godfrey Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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>
Group 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>
Group 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>
Group Member
Sun 30 Sep 2012 01:51:25 AM UTC, comment #9: 

What does Matlab do for the following?


x = -0
1/x
x = 1/-Inf
1/x


?

John W. Eaton <jwe>
Group 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>
Group 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>
Group 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>
Group 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>
Group 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>
Group 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>
Group Member
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>
Group 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>
Group Member
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>
Group Member

 

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

Attach Files:
   
   
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
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by jordigh (Posted a comment)
  • -email is unavailable- added by godfrey (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-09-30 godfrey Attached File- Added sign_doc1.diff, #26669
    2012-09-28 jordigh StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code