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

 
 

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

Submitted by:  Kamaraju Kusumanchi <kamaraju>
Submitted on:  Fri 06 Apr 2012 05:29:36 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: FixedAssigned to: Rik <rik5>
Originator Name: Kamaraju S. KusumanchiOpen/Closed: Closed
Release: 3.2.4Operating System: GNU/Linux

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)

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>
Project AdministratorIn charge of this item.
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+pii, pi+1e8i])

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.

Rik <rik5>
Project AdministratorIn charge of this item.
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.

Rik <rik5>
Project AdministratorIn charge of this item.
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?

Rik <rik5>
Project AdministratorIn charge of this item.
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>
Project 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?

Rik <rik5>
Project AdministratorIn charge of this item.
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 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 godfrey (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by kamaraju (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 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 09 Apr 2012 02:55:41 AM UTCrik5StatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Sun 08 Apr 2012 04:27:23 AM UTCrik5StatusNeed Info=>In Progress
      Assigned toNone=>rik5
    Fri 06 Apr 2012 10:09:40 PM UTCrik5StatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup1