bugGNU Octave - Bugs: bug #45174, num2str produces different results...

 
 

bug #45174: num2str produces different results from Matlab for some corner cases

Submitted by:  Rik <rik5>
Submitted on:  Sun 24 May 2015 04:58:19 AM UTC  
 
Category: Octave FunctionSeverity: 2 - Minor
Priority: 3 - LowItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission Jump to the original submission)

Wed 17 Jun 2015 07:55:53 PM UTC, comment #6:

I rebased your cset to the dev branch and applied it here (http://hg.savannah.gnu.org/hgweb/octave/rev/f357e076776f)

With regards to comment #2 and and when the '%e' format should be applied, the documentation says:

Thus, it appears to apply only to the %s and %c conversions which your patch covers.

Rik <rik5>
Project Administrator
Wed 17 Jun 2015 02:59:03 PM UTC, comment #5:

The attached patch solves these bugs and adds some tests.

The patch also solves bug #44684

I haven't touched the case for complex numbers/matrices. Can anyone check if the outputs are correct (respect to matlab).

(file #34245)

Juan Pablo Carbajal <juanpi>
Project Member
Wed 17 Jun 2015 01:22:21 PM UTC, comment #4:

The result I get from Matlab (R2015a) is:

The use of sprintf is the better option. But the option with num2str was in a Matlab Code I tried to use in Octave.

Anonymous
Wed 17 Jun 2015 01:07:30 PM UTC, comment #3:

The bug in comment #1 is caused at line ~119 of num2str where it says

This line assumes that the fmt input is only a format string and nothing else, and applies the same for all columns of x.

The use of num2str in comment #1 seems incorrect to me, sprintf should be used instead. What does matlab do when the format string of num2str is "sometext_%d_%d"?

Juan Pablo Carbajal <juanpi>
Project Member
Wed 17 Jun 2015 12:41:58 PM UTC, comment #2:

Can anybody test in Matlab what are the result of

num2str(e ,"%d")
num2str(e ,"%i")
num2str(e ,"%u")
num2str(e ,"%o")
num2str(e ,"%x")
num2str(e ,"%X")
num2str(e ,"%f")
num2str(e ,"%F")
num2str(e ,"%E")
num2str(e ,"%a")
num2str(e ,"%A")

I am trying to guess when %e should be set by default. Is it only when the format string is "%c" or "%s"?

Juan Pablo Carbajal <juanpi>
Project Member
Wed 17 Jun 2015 10:47:36 AM UTC, comment #1:

A additional case where num2str fails:

With 2 or more numbers to convert a wrong answer is returned:

Octave adds characters before the first number after the end of the string.

With 1 number the answer is correct:

and if the first number is close enough to the beginning:

Anonymous
Sun 24 May 2015 04:58:19 AM UTC, original submission:

Corner case 1 : %s on integer values

This is supposed to produce a string where the integers are interpreted as ASCII characters as long as they are in the appropriate range. Octave almost succeeds, but truncates the string by one character.

Corner case 2 : wrong conversion for type of numeric input, should default to '%e'

If you use an incorrect format, Octave is supposed to recognize that the data is not correct and switch to the '%e' format. For example,

Rik <rik5>
Project Administrator

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #34245:  num2str.diff added by juanpi (2KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by juanpi (Posted a comment)
  • -unavailable- added by mtmiller (Updated the item)
  • -unavailable- added by rik5 (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 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 17 Jun 2015 07:55:53 PM UTCrik5StatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Wed 17 Jun 2015 02:59:02 PM UTCjuanpiAttached File-=>Added num2str.diff, #34245
    Mon 25 May 2015 03:09:47 AM UTCrik5Summarynum2str produces differently results from Matlab for some corner cases=>num2str produces different results from Matlab for some corner cases
    Sun 24 May 2015 06:14:10 PM UTCmtmillerSummarynumstr produces differently results from Matlab for some corner cases=>num2str produces differently results from Matlab for some corner cases
    Sun 24 May 2015 04:58:40 AM UTCrik5Priority5 - Normal=>3 - Low
      Summarynumstr produces differently sized results from Matlab for some corner cases=>numstr produces differently results from Matlab for some corner cases

    Back to the top


    Powered by Savane 3.1-cleanup1