bugGNU Octave - Bugs: bug #43369, rats has some internal overflow

 
 

bug #43369: rats has some internal overflow

Submitter:  Colin Macdonald <cbm>
Submitted:  Mon 06 Oct 2014 11:08:35 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  andy1978
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.2 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 27 Nov 2014 08:10:52 PM UTC, comment #6: 

I've pushed a cset c490eac28bbb to stable which fixes the overflow. I'll close this bugreport as fixed and open a new report which addresses the remaining matlab incompatibility for rats strlen.

Andreas Weber <andy1978>
Group Member
Fri 21 Nov 2014 08:49:03 AM UTC, comment #5: 

Pong! It's not as simple as I first thought it would be. As I see now, Matlabs rats behaves different regarding to "strlen". Their documentation on http://mathworks.com/help/matlab/ref/rats.html More About -> Algorithms says they calculate the tolerance dynamically. I'll ask on the mailinglist for some Matlab outputs.

Andreas Weber <andy1978>
Group Member
Thu 20 Nov 2014 10:14:33 PM UTC, comment #4: 

Ping!  Andreas, I think you can go ahead and wrap your patch up with some comments into a changeset and commit it to the stable branch.

Rik <rik5>
Group administrator
Mon 27 Oct 2014 07:45:48 PM UTC, comment #3: 

This seems like an important enough fix that it should be put on the stable branch.

Also, I tested the patch on the dev branch and it works just fine there.

Rik <rik5>
Group administrator
Tue 07 Oct 2014 05:35:37 PM UTC, comment #2: 

I've also had a look, is the attached patch okay and if yes, to which branch should it go?

(file #32238)

Andreas Weber <andy1978>
Group Member
Tue 07 Oct 2014 03:06:18 PM UTC, comment #1: 

The trouble is this line in libinterp/corefcn/pr-output.cc:rational_approx at about line 404.  The loop stopping criteria above this statement should be checking that the numerator (n) and the denominator (d) have not exceeded std::numeric_limits<int>::max ()).


          buf << std::setprecision (0) << static_cast<int>(n)
              << "/" << static_cast<int>(d);



Rik <rik5>
Group administrator
Mon 06 Oct 2014 11:08:35 PM UTC, original submission:  

Consider:

octave:33> rats(2.005, 25)
ans =                   401/200
octave:34> rats(2.0005, 25)
ans =   -2147483648/-2147483648


Matlab seems ok.  "rats(pi, N)" seems to max out at "80143857/25510582" (with error 2*eps) at around N=30 but still produces that string with additional padding for N=1000.

Colin Macdonald <cbm>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #32238:  pr-output.cc.diff added by andy1978 (1KiB - 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 andy1978 (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by cbm (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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-11-27 andy1978 StatusIn Progress Fixed
        Open/ClosedOpen Closed
        Releasedev 3.8.2
    2014-10-27 rik5 StatusConfirmed In Progress
        Assigned toNone andy1978
    2014-10-07 andy1978 Attached File- Added pr-output.cc.diff, #32238
    2014-10-07 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code