bugGNU Octave - Bugs: bug #36117, datenum does not understand...

 
 

bug #36117: datenum does not understand default output of num2str

Submitter:  Kamaraju Kusumanchi <kamaraju>
Submitted:  Fri 06 Apr 2012 05:29:36 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  rik5
Originator Name:  Kamaraju S. Kusumanchi Open/Closed:  * Closed
Release:  * 3.2.4 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 09 Apr 2012 02:55:41 AM UTC, comment #10: 

Fixed on the development branch in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/34c932e669c8).  To access the fix you will need to build from Mercurial sources or wait until the 3.8.0 release.

To solve your immediate problem you can use your workaround, use sprintf ("%d", your_number), or use int2str() which specifically produces an integer output.

Rik <rik5>
Group administrator
Sun 08 Apr 2012 06:42:35 AM UTC, comment #9: 

Here is the output. Please do not hesitate if you need more information. The more corner cases we can attack, the better.

>> num2str (2 * bitmax)


num2str (20 * bitmax)

num2str (realmax)

num2str (1.2e-34)

num2str ([1.2e-34, pi*1e30])

num2str ([true false true])

num2str ([0+1i, 1+0i, 1+1i])

num2str ([1e8+pi*i])

num2str ([pi+1e8*i])

num2str ([1e8+pi*i, pi+1e8*i])

num2str ([.123456, .000123456])

num2str ([0.22967, -0.59991; 0.51811, 0.82158], 3)

num2str (pi, -1)

num2str (Inf)

num2str (NaN)



ans =



18014398509481982





ans =



180143985094819810





ans =



179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000





ans =



1.2e-034





ans =



1.2e-034 3.141592653589793e+030





ans =



1  0  1





ans =



0+1i   1+0i   1+1i





ans =



100000000+3.14159265359i





ans =



3.14159265359+100000000i





ans =



100000000+3.14159265359i                 3.14159265359+100000000i





ans =



0.12346  0.00012346





ans =



 0.23      -0.6

0.518     0.822





ans =



3.14159





ans =



Inf





ans =



NaN



>>

Kamaraju Kusumanchi <kamaraju>
Sun 08 Apr 2012 04:49:46 AM UTC, comment #8: 

I have an implementation that works on most ordinary real inputs.  I'm going to ask for some more data on various corner cases.  Some of these may throw errors, but that would be interesting.


num2str (2 * bitmax)
num2str (20 * bitmax)
num2str (realmax)
num2str (1.2e-34)
num2str ([1.2e-34, pi*1e30])
num2str ([true false true])
num2str ([0+1i, 1+0i, 1+1i])
num2str ([1e8+pi*i])
num2str ([pi+1e8*i])
num2str ([1e8+pi*i, pi+1e8*i])
num2str ([.123456, .000123456])
num2str ([0.22967, -0.59991; 0.51811, 0.82158], 3)
num2str (pi, -1)
num2str (Inf)
num2str (NaN)


Rik <rik5>
Group administrator
Sat 07 Apr 2012 07:01:34 PM UTC, comment #7: 


>> num2str ([1e8, pi; 1234, eps])




ans =



100000000       3.14159265359

     1234  2.22044604925e-016


Kamaraju Kusumanchi <kamaraju>
Sat 07 Apr 2012 06:51:08 PM UTC, comment #6: 

One last test piece of code to verify in Matlab.


num2str ([1e8, pi; 1234, eps])


Rik <rik5>
Group administrator
Sat 07 Apr 2012 05:47:35 PM UTC, comment #5: 


>> num2str (pi)


num2str ([1e6*pi, pi])

num2str (2^33)

num2str (bitmax () + 10)



ans =



3.1416





ans =



3141592.6536      3.1415926536





ans =



8589934592





ans =



9007199254741000

Kamaraju Kusumanchi <kamaraju>
Sat 07 Apr 2012 04:59:31 PM UTC, comment #4: 

This is not what I expected.  It seems that Matlab detects integers specifically and always displays as many digits as possible.  Could I get a few more tests done?


num2str (pi)
num2str ([1e6*pi, pi])
num2str (2^33)
num2str (bitmax () + 10)


Rik <rik5>
Group administrator
Sat 07 Apr 2012 12:48:04 AM UTC, comment #3: 

Confirm that the behavior in Matlab 7.9.1.671 (R2009b) Service Pack 1 is same as posted by Michael Godfrey.

Kamaraju Kusumanchi <kamaraju>
Fri 06 Apr 2012 10:18:42 PM UTC, comment #2: 


>> num2str (1e6)


ans =

1000000

>> num2str (1e7)


ans =

10000000

>> num2str (1e8)


ans =

100000000

>> num2str (1e9)


ans =

1000000000

>> num2str (1e10)


ans =

10000000000

>>
>> num2str ([1e8, pi])


ans =

100000000       3.14159265359

>> version


ans =

7.9.0.529 (R2009b)

>>


Michael Godfrey <godfrey>
Group Member
Fri 06 Apr 2012 10:09:40 PM UTC, comment #1: 

The issue you identify is with the output format of num2str.  Since you have access to Matlab, can you verify how Matlab handles large integers in num2str?


num2str (1e6)
num2str (1e7)
num2str (1e8)
num2str (1e9)
num2str (1e10)

num2str ([1e8, pi])


Rik <rik5>
Group administrator
Fri 06 Apr 2012 05:29:36 PM UTC, original submission:  

Using octave 3.2.4 on Debian Wheezy

$octave -qf
octave:1> datenum('20120401', 'yyyymmdd')
ans =  734960
octave:2> datenum(num2str(20120401), 'yyyymmdd')
error: datevec: date not parsed correctly with given format
error: called from:
error:   /usr/share/octave/3.2.4/m/time/datevec.m at line 140, column 11
error:   /usr/share/octave/3.2.4/m/time/datenum.m at line 75, column 25
octave:2>

FWIW, the command works under matlab 7.9.1.671 (R2009b) Service Pack 1.

As highlighted in http://octave.1599824.n4.nabble.com/datenum-does-not-understand-num2str-td4524748.html , the workaround is to use

octave:3> datenum(num2str(20120401,8), 'yyyymmdd')
ans =  734960

When no arguments are provided, num2str(20120401) should just produce 20120401 and not 2.01204e+07. This ensures compatibility with matlab and enables datenum, num2str to speak with each other.

thanks
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/

Kamaraju Kusumanchi <kamaraju>

 

(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 godfrey (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by kamaraju (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-04-09 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2012-04-08 rik5 StatusNeed Info In Progress
        Assigned toNone rik5
    2012-04-06 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code