bugGNU Octave - Bugs: bug #59527, num2str: percent sign removes...

 
 

bug #59527: num2str: percent sign removes newline for column vector

Submitter:  Felipe G. Nievinski <fgnievinski>
Submitted:  Tue 24 Nov 2020 12:48:46 AM 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:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Nov 2020 09:43:32 PM UTC, comment #4: 

I made the diff in to a full changeset and checked it in under jwe's name here: http://hg.savannah.gnu.org/hgweb/octave/rev/51bb0e599af4.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Wed 25 Nov 2020 10:38:45 PM UTC, comment #3: 

@jwe: Your diff works for the example code in this bug report.  I also tried a different formulation of the test using regexp() to see if there was a performance difference:


tic; numel (regexp (fmt, '(?<!%)%(?!%)', 'start')) > 1; toc


It is about 2x slower (although still only .3 milliseconds) compared to staying entirely within Octave character matrices (~.15 milliseconds).

I think it's fine to convert the diff to a true changeset.

Rik <rik5>
Group administrator
Tue 24 Nov 2020 03:40:29 PM UTC, comment #2: 

The problem seems to be the check for more than one format specifier here:

http://hg.savannah.gnu.org/hgweb/octave/file/d09dde091073/scripts/general/num2str.m#l133

That check was added in the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/annotate/f357e076776f/scripts/general/num2str.m#l122

Maybe skip "%%" in the format using something like the attached change?  I don't know whether this quick fix could be fooled in some other ways though, so a better check for format specifiers may be needed.  Either way, we could uses tests for these cases, of course..


(file #50334)

John W. Eaton <jwe>
Group administrator
Tue 24 Nov 2020 01:51:23 AM UTC, comment #1: 

Confirmed.  Changing the release to "dev" since this is probably tricky and won't be resolved in time for the 6.1 release.

Rik <rik5>
Group administrator
Tue 24 Nov 2020 12:48:46 AM UTC, original submission:  

this works fine:

>> num2str([1;2], '%f')

ans =
1.000000
2.000000

arbitrary text in the formatis also fine:

>> num2str([1;2], '%fsometext')

ans =
1.000000sometext
2.000000sometext

but a literal percent sign causes newline to be removed when a column vector is input:

>> num2str([1;2], '%f%%')

ans = 1.000000%2.000000%

in matlab, this is:

>> num2str([1;2], '%f%%')

ans =
  2×9 char array
    '1.000000%'
    '2.000000%'

related bug: #45174

Felipe G. Nievinski <fgnievinski>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #50334:  num2str-diffs.txt added by jwe (584B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2020-11-30 rik5 StatusPatch Reviewed Fixed
        Open/ClosedOpen Closed
    2020-11-25 rik5 StatusConfirmed Patch Reviewed
    2020-11-24 jwe Attached File- Added num2str-diffs.txt, #50334
    2020-11-24 rik5 CategoryNone Octave Function
        StatusNone Confirmed
        Release5.2.0 dev
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code