bugGNU Octave - Bugs: bug #50947, angle of -0-0i should be 0

 
 

bug #50947: angle of -0-0i should be 0

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Thu 04 May 2017 02:05:29 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  WTF, Matlab?!?
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.1 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 15 Sep 2017 08:18:58 PM UTC, comment #13: 

Marking as "Won't Fix" and closing.

Rik <rik5>
Group administrator
Tue 05 Sep 2017 04:49:12 AM UTC, comment #12: 

Is there anything that we want to change in Octave for this bug report, or should it be marked "Won't Fix"?.

Rik <rik5>
Group administrator
Sun 07 May 2017 06:12:20 AM UTC, comment #11: 

Yes.

Although these results are still significantly different from MATLAB.

>>  atan2 (0, -0)

ans =  3.1416

>> angle(-0-0i)

ans =  3.1416

>>

Ceral Paquet <octavebugs>
Thu 04 May 2017 07:17:01 PM UTC, comment #10: 

Yeah, so Matlab doesn't throw away the signed zero, it just doesn't display it.  And then it uses it inconsistenly.

I think it's a bug in Octave that the constant 0-0i is narrowed to a real value.  That seems bad to me, but most people don't seem to care about that.

John W. Eaton <jwe>
Group administrator
Thu 04 May 2017 06:50:54 PM UTC, comment #9: 


>> x = -1/Inf
1/x

x =

     0


ans =

  -Inf


Ceral Paquet <octavebugs>
Thu 04 May 2017 06:49:33 PM UTC, comment #8: 


>> x = -1/Inf


x =

     0

Ceral Paquet <octavebugs>
Thu 04 May 2017 06:48:47 PM UTC, comment #7: 

I just found this web page that discusses signed zeros in MATLAB. It's not very encouraging.

https://www.advanpix.com/2016/04/28/branch-cuts-and-signed-zeros-in-matlab/

So this is probably more a WTF!? MATLAB issue than a bug.

Ceral Paquet <octavebugs>
Thu 04 May 2017 06:48:18 PM UTC, comment #6: 

Finally, what does Matlab do for the following:


x = -1/Inf
1/x


John W. Eaton <jwe>
Group administrator
Thu 04 May 2017 05:54:00 PM UTC, comment #5: 

Response using myatan2 mex:

MATLAB

>> myatan2 (0, 0)
myatan2 (0, 0) = 0

>> myatan2 (-0, 0)
myatan2 (-0, 0) = -0

>> myatan2 (0, -0)
myatan2 (0, -0) = 3.14159

>> myatan2 (-0, -0)
myatan2 (-0, -0) = -3.14159

>> atan2 (0, 0)
ans =     0

>> atan2 (-0, 0)
ans =     0

>> atan2 (0, -0)
ans =     0

>> atan2 (-0, -0)
ans =     0


Ceral Paquet <octavebugs>
Thu 04 May 2017 05:50:31 PM UTC, comment #4: 

Response using myfunc mex:

MATLAB

>> myfunc (-0)
-0
>> myfunc (-0+0i)
0
>> myfunc (-0-0i)
-0
>> myfunc (complex (-0, 0))
(-0, 0)
>> myfunc (complex (-0, -0))
(-0, -0)
>> neg_zero = -0;
>> myfunc (neg_zero)
-0


Ceral Paquet <octavebugs>
Thu 04 May 2017 04:20:27 PM UTC, comment #3: 

Also, with the attached MEX file myatan2.c, please try the following with Matlab and report back what it displays:


myatan2 (0, 0)
myatan2 (-0, 0)
myatan2 (0, -0)
myatan2 (-0, -0)

atan2 (0, 0)
atan2 (-0, 0)
atan2 (0, -0)
atan2 (-0, -0)



(file #40581)

John W. Eaton <jwe>
Group administrator
Thu 04 May 2017 04:15:41 PM UTC, comment #2: 

I think this is more of an issue about automatic narrowing and whether Matlab keeps the sign bit on an IEEE 0.

Because storing complex numbers requires double the amount of storage (real and imaginary 8-byte numbers), Octave automatically tries to compact to a real array whenever the complex part is equal to zero.  Try the failing code in two steps:


octave:1> x = -0-0i
x = -0
octave:2> angle (x)
ans =  3.1416
octave:3> angle (-x)
ans = 0


In the first stage, Octave compacts the value to '-0'.  And the angle of -0 is pi.  Does Matlab keep the signbit for zero values?  What does the following return in Matlab?


atan2 (0,0)
atan2 (0,-0)
atan2 (-0,-0)
atan2 (-0,0)


In Octave


octave:7> atan2 (0,0)
ans = 0
octave:8> atan2 (0,-0)
ans =  3.1416
octave:9> atan2 (-0,-0)
ans = -3.1416
octave:10> atan2 (-0,0)
ans = -0



Rik <rik5>
Group administrator
Thu 04 May 2017 04:13:14 PM UTC, comment #1: 

Could someone please take the attached MEX file, myfunc.c, and try it with Matlab and report back what it displays for the following:


myfunc (-0)
myfunc (-0+0i)
myfunc (-0-0i)
myfunc (complex (-0, 0))
myfunc (complex (-0, -0))

neg_zero = -0
myfunc (neg_zero)



(file #40580)

John W. Eaton <jwe>
Group administrator
Thu 04 May 2017 02:05:29 PM UTC, original submission:  


Octave 4.2.1

>> angle(0+0i)
ans = 0
>> angle(0-0i)
ans = 0
>> angle(-0-0i)
ans =  3.1416
>> angle(-0+0i)
ans = 0


MATLAB

>> angle(0+0i)

ans =

     0

>> angle(0-0i)

ans =

     0

>> angle(-0-0i)

ans =

     0

>> angle(-0+0i)

ans =

     0


Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #40581:  myatan2.c added by jwe (333B - text/x-csrc)
file #40580:  myfunc.c added by jwe (337B - text/x-csrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by octavebugs (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-09-15 rik5 StatusNone Wont Fix
        Open/ClosedOpen Closed
    2017-05-04 jwe Item GroupNone WTF, Matlab?!?
    2017-05-04 jwe Attached File- Added myatan2.c, #40581
        Item GroupMatlab Compatibility None
        Summaryangle of -0-0i should be 0 for Matlab compatibility angle of -0-0i should be 0
    2017-05-04 rik5 Item GroupNone Matlab Compatibility
        Summaryangle of -0-0i should be 0 angle of -0-0i should be 0 for Matlab compatibility
    2017-05-04 jwe Attached File- Added myfunc.c, #40580

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code