bugGNU Octave - Bugs: bug #57704, Exactly Matlab compatible behavior...

 
 

bug #57704: Exactly Matlab compatible behavior for rats?

Submitted by:  Rik <rik5>
Submitted on:  Fri 31 Jan 2020 02:00:07 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 31 Jan 2020 02:37:49 AM UTC, comment #1: 

Hmm, one thing I notice in Matlab is that the returned string is actually one longer than the length argument. So

>> rats (2.0005, 9)
ans = ' 4001/2000'

returns a string of length 10. If it is negative,

>> rats (-2.0005, 9)
ans = '     *    '

the return value is still length 10, but a star because the negative sign leaves no room for the space at the beginning.

So it looks to me like at least one leading space is always present, and doesn't count against the number of characters the user requested.

I think the point of this additional leading space is so the user can just slap the strings together and they are implicitly space-padded. And no extra space needs to be inserted when operating on a row vector, for example

>> x = rand (1, 2);
>> size (rats (x(1), 10))
ans =
    1   11
>> size (rats (x, 10))
ans =
    1   22

IMHO it would be nice to be compatible in all of these cases.

Mike Miller <mtmiller>
Project Administrator
Fri 31 Jan 2020 02:00:07 AM UTC, original submission:  

rats() has been much improved for the 6.1 release of Octave.  However, it is still not identical to Matlab.  Do we care enough to spend programmer time on this issue?

Example 1:

assert (rats (2.0005, 9), "4001/2000");

Octave produces "2" in this case, although if the string length is updated to 10 then the same answer is had.  This is because Octave reserves one extra character for the minus sign in case it is present.  It isn't present here, but the reservation has already occurred.

Example 2:

assert (rats (123, 2), " *");

Octave produces "123" which does seem incorrect.

Rik <rik5>
Project Administrator

 

(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 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.5