bugGNU Octave - Bugs: bug #38463, num2str output inconsistent with...

 
 

bug #38463: num2str output inconsistent with sprintf

Submitted by:  Nir Krakauer <nir_krakauer>
Submitted on:  Mon 04 Mar 2013 05:13:34 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: Nir KrakauerOpen/Closed: Closed
Release: 3.6.2Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Tue 05 Mar 2013 10:04:13 PM UTC, comment #5:

Octave is pursuing consistency with Matlab in this regard. I have changed the documentation to note that leading spaces will be trimmed before returning the converted string (http://hg.savannah.gnu.org/hgweb/octave/rev/576daea679fe). Closing report.

Rik <rik5>
Project Administrator
Tue 05 Mar 2013 06:45:08 PM UTC, comment #4:

2013a:

Philip Nienhuis <philipnienhuis>
Project Member
Tue 05 Mar 2013 12:23:15 AM UTC, comment #3:

This seems pretty easy to fix. The m-file essentially has

as the last line of code in the file. If you remove the strtrim it doesn't strip out spaces and I get the same result as Matlab.

What does Matlab return for these two pieces of code?

Rik <rik5>
Project Administrator
Mon 04 Mar 2013 06:16:05 PM UTC, comment #2:

ML r2013a prerelease:

>> num2str(5, '%2.0d')


ans =

5

>> sprintf('%2.0d', 5)


ans =

5

>>

Philip Nienhuis <philipnienhuis>
Project Member
Mon 04 Mar 2013 05:23:23 PM UTC, comment #1:

Could you check to see what Matlab does for each of these?

It may work like this because it is trying to be 100% compatible with Matlab.

John W. Eaton <jwe>
Project Administrator
Mon 04 Mar 2013 05:13:34 PM UTC, original submission:

num2str(5, "%2.0d")
returns
5
(no initial space)

sprintf("%2.0d", 5)
returns
5
(with initial space, which is what would be expected)

Nir Krakauer <nir_krakauer>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by nir_krakauer (Submitted the item)
  •  

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

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 05 Mar 2013 10:04:13 PM UTCrik5StatusNone=>Fixed
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1