bugGNU Octave - Bugs: bug #43367, rats overly eager to use asterisks

 
 

bug #43367: rats overly eager to use asterisks

Submitter:  Colin Macdonald <cbm>
Submitted:  Mon 06 Oct 2014 11:01:59 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
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
   

Thu 27 Nov 2014 08:19:14 PM UTC, comment #2: 

Fixed in cset c490eac28bbb. There is still a matlab incompatibility: Octave tries to find an approximation which fits into LEN (second arg of rats) but Matlab seems to do some fancy stuff to calculate a tolerance from LEN and then call rat with this tolerance.

For example octave returns 22/7 for rats(pi, 4) whereas Matlab returns "  *", see http://octave.1599824.n4.nabble.com/Matlab-output-from-quot-rats-quot-wanted-tt4667406.html

I'm closing this report because the original problem (numerator/denumerator overflow) is fixed.

Andreas Weber <andy1978>
Group Member
Tue 07 Oct 2014 02:58:54 PM UTC, comment #1: 

Yes it is.  The problem seems to be in the stopping criteria for the rational approximation.  The routine to investigate is


rational_approx (double val, int len)


which is located in libinterp/corefcn/pr-output.cc at line 346.



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

Octave:

octave:24> rats([2.5 2.05 2.005 2.0005 2.00005 2.000005 pi], 5)
ans =     5/2  41/20      *      *      *      *   22/7


Matlab:

rats([2.5 2.05 2.005 2.0005 2.00005 2.000005 pi], 5)
ans =
  5/2    2     2     2     2     2   22/7


I find Matlab rats more pleasant ;-)

I think the interpretation of the LEN parameter (5 in my examples) should be: try to find a rational approximation that fits in this many characters and return "*" otherwise.

For example, both Octave and Matlab will use "*" for "rats(pi, 3)".

None of this seems to be documented, but I will file a separate issue for that.

Colin Macdonald <cbm>

 

(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 andy1978 (Posted a comment)
  • -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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-11-27 andy1978 StatusConfirmed Fixed
        Open/ClosedOpen Closed
        Releasedev 3.8.2
    2014-10-07 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code