bugGNU Octave - Bugs: bug #53496, mod: mod(nx,-x) producing -0

 
 

bug #53496: mod: mod(nx,-x) producing -0

Submitter:  Dildar Sk <hodor123456>
Submitted:  Wed 28 Mar 2018 08:13:44 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Works For Me Assigned to:  None
Originator Name:  Dildar Sk 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

Wed 28 Mar 2018 06:03:09 PM UTC, comment #7: 

I filed a new issue report about adding a more extensive FAQ at bug #53502.

Closing this report.

Rik <rik5>
Group administrator
Wed 28 Mar 2018 03:23:42 PM UTC, comment #6: 

Yes, Rik, same here.
I think Jwe is right in putting newcomer's questions
wrapped up in a FAQ. I will try my best to contribute
there.

Dildar Sk <hodor123456>
Wed 28 Mar 2018 03:20:35 PM UTC, comment #5: 

"What does it show",


x = mod (11, -1);
1/x


Yes,it showing -inf in both Octave and MATLAB.
I now can understand that there is some meaning in floating
point arithmetic.

Dildar Sk <hodor123456>
Wed 28 Mar 2018 03:20:05 PM UTC, comment #4: 

I like jwe's suggestion to have a FAQ or other compilation of issues that are most likely to trip up new users.

Rik <rik5>
Group administrator
Wed 28 Mar 2018 11:16:09 AM UTC, comment #3: 

Signed zero is required by IEEE 754, which Octave follows (and Matlab too, I think). Whether it is sensible to return -0 here I have no idea, but I also don't see when it is sensible to compute modulo negative integers. But before you call this a Matlab incompatibility, try 1/mod(12,-3), because Matlab also handles -0, but just doesn't display it.

Michael Leitner <mleitner>
Wed 28 Mar 2018 11:16:06 AM UTC, comment #2: 

Oops, that AC_INIT  and the following line were accidentally pasted in my previous comment.

John W. Eaton <jwe>
Group administrator
Wed 28 Mar 2018 11:14:36 AM UTC, comment #1: 

Matlab may compute -0, but it doesn't display it.

What does


x = mod (11, -1);
1/x


show you?  If the result of 1/x is -Inf, then x is -0, but it is not displayed.  I think it makes sense to display the value as -0, since that has meaning in floating point arithmetic.

That you have been finding things that are well known but may be confusing to new users makes me think that it might be good to have them all documented in a single place.  The FAQ on the wiki might be a good place if these items are not already there.  Things I can think of now are

  • Inf * i ==> (NaN + InfI)


  • Computation and display of -0


  • Comparison of complex numbers with <, <=, >, >= vs. min and max functions


  • String class vs. character arrays


  • What it means for Octave to be compatible with Matlab


Anything else?


AC_INIT([GNU Octave], [4.3.0+], https://octave.org/bugs.html, [octave])

>>>>>>> merge rev


John W. Eaton <jwe>
Group administrator
Wed 28 Mar 2018 08:13:44 AM UTC, original submission:  

In MATLAB,


>> mod(11,-1)

ans =

     0

>> mod(12,-2)

ans =

     0

>> mod(15,-3)

ans =

     0

>>


In Octave,


>> mod(13,-1)
ans = -0
>> mod(12,-3)
ans = -0
>> mod(15,-3)
ans = -0


So, for any integer n,x mod(nx,-x) giving -0.
What's the point of producing -0 when 0 and -0 is
same?

Dildar Sk <hodor123456>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

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 mleitner (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by hodor123456 (Submitted the item)
  • -email is unavailable- added by hodor123456
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-28 rik5 StatusNeed Info Works For Me
        Open/ClosedOpen Closed
    2018-03-28 rik5 StatusNone Need Info
    2018-03-28 hodor123456 Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code