bugGNU Octave - Bugs: bug #36121, num2str(2.4e9,15) gives incorrect...

 
 

bug #36121: num2str(2.4e9,15) gives incorrect result

Submitted by:  Sebastian Held <sibbi77>
Submitted on:  Sat 07 Apr 2012 10:31:39 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: Rik <rik5>
Originator Name: Open/Closed: Closed
Release: 3.6.1Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Mon 09 Apr 2012 02:58:51 AM UTC, comment #4:

Fixed 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.

For an immediate fix, use the 'l' modifier to sprintf.

Rik <rik5>
Project AdministratorIn charge of this item.
Sun 08 Apr 2012 05:03:04 PM UTC, comment #3:

You are right. This seems to be a problem on 64 bit systems. When I used Debian wheezy, 64bit machine I can reproduce this problem.

$ octave -q

warning: mark_as_command is obsolete and will be removed from a future version of Octave

octave:1> num2str(2.4e9,15)

ans = -1894967296

octave:2> version

ans = 3.2.4

octave:3> which num2str

`num2str' is a function from the file /usr/share/octave/3.2.4/m/general/num2str.m

octave:4> sprintf('%d',double(intmax))

ans = 2147483647

octave:5> sprintf('%d',double(intmax)+1)

ans = -2147483648

If I use the same commands on Debian Wheezy, 32 bit machine I get

$octave -q
octave:1> num2str(2.4e9,15)
ans = 2400000000
octave:2> version
ans = 3.2.4
octave:3> which num2str
`num2str' is a function from the file /usr/share/octave/3.2.4/m/general/num2str.m
octave:4> sprintf('%d',double(intmax))
ans = 2147483647
octave:5> sprintf('%d',double(intmax)+1)
ans = 2147483648

Kamaraju Kusumanchi <kamaraju>
Sun 08 Apr 2012 10:33:52 AM UTC, comment #2:

My octave 3.2.4 on Ubuntu Precise (and Natty, both 32bit) does also not show this problem, but on my 64bit gentoo box this happens:

But I have reports from two other people seeing this problem (see thread at http://openems.de/forum/viewtopic.php?f=2&t=24&p=146#p146 )

May it be possible that this only shows up on 64 bit systems?

By the way:

Sebastian Held <sibbi77>
Sat 07 Apr 2012 05:53:39 PM UTC, comment #1:

I am unable to reproduce your result on octave 3.2.4, Debian Wheezy GNU/Linux.

octave:1> num2str(2.4e9,15)
ans = 2400000000
octave:2> version
ans = 3.2.4
octave:3> which num2str
`num2str' is a function from the file /usr/share/octave/3.2.4/m/general/num2str.m

what is the output of 'which num2str' function?

Kamaraju Kusumanchi <kamaraju>
Sat 07 Apr 2012 10:31:39 AM UTC, original submission:

the num2str() function has a flaw concerning large numbers.
If a number is smaller than 10^<given precision>, the sprintf format is '%d', but this format is limited to intmax.

Example:

num2str.m should be fixed to include an additional check, if the number is below intmax, otherwise %g or %f must be used.

Sebastian Held <sibbi77>

 

(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 (Updated the item)
  • -unavailable- added by kamaraju (Posted a comment)
  • -unavailable- added by sibbi77 (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 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 09 Apr 2012 02:58:51 AM UTCrik5StatusIn Progress=>Fixed
      Open/ClosedOpen=>Closed
    Sun 08 Apr 2012 04:26:51 AM UTCrik5StatusNone=>In Progress
      Assigned toNone=>rik5

    Back to the top


    Powered by Savane 3.1-cleanup1