bugGNU Octave - Bugs: bug #36278, Sprintf %d bugs

 
 

bug #36278: Sprintf %d bugs

Submitted by:  None
Submitted on:  Tue 24 Apr 2012 04:14:26 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Priority: 3 - LowItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: deegoOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 3.2.4
Operating 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)

Fri 03 Jan 2014 08:17:48 PM UTC, comment #7:

I checked in the following change:

http://hg.savannah.gnu.org/hgweb/octave/rev/8c92b5e7fa4d

Given all the other things that happen before we send the value off to the C or C++ library for printing, it seems like this change will have a very small effect on performance.

John W. Eaton <jwe>
Project Administrator
Thu 14 Mar 2013 05:06:08 PM UTC, comment #6:

It would be nice if the C library behaved a bit
more reasonably:
octave:1> sprintf ('%d', 1.3e15)
ans = -701153280

could confuse people, particularly if the
results go to someplace other than the screen.

Is it hard and inefficient, to replace the
wrong answer with something like "OVFL"?
This would tend to prevent using the wrong
result as data.

Michael Godfrey <godfrey>
Project Member
Thu 14 Mar 2013 04:43:45 PM UTC, comment #5:

From Michael's testing,

Matlab appears to be fiddling with the format conversion string when the result would overflow. In this case, '%d' is replaced by '%e'.

Seems like there would be quite a penalty to check all numbers against the format string rather than just handing everything over to the underlying C library routine.

It is definitely a compatibility issue, but maybe we don't want to fix it.

Rik <rik5>
Project Administrator
Thu 14 Mar 2013 04:03:34 PM UTC, comment #4:

Could someone with Matlab test definitively what is done for input arguments which exceed the '%d' range?

For Octave on a 64-bit architecture, the first sprintf is negative (wrong) while the second is correct.

Rik <rik5>
Project Administrator
Tue 24 Apr 2012 01:10:55 PM UTC, comment #3:

I can confirm both of these differences now, I only had 64-bit Octave available earlier.

Dave, please post replies to the bug tracker interface.

Copying Dave's followup message here, this sounds like two different bugs now.

Mike Miller <mtmiller>
Project Administrator
Tue 24 Apr 2012 11:51:29 AM UTC, comment #2:

I think this problem is a compatibility issue, so I'm reopening the report.

It looks like Matlab switches to a %e format if the value contains a fractional part or would overflow the specified integer conversion.

John W. Eaton <jwe>
Project Administrator
Tue 24 Apr 2012 11:23:54 AM UTC, comment #1:

This is not a bug, your value is larger than what can be handled by the %d format specifier, regardless of 32-bit or 64-bit architecture. Use %ld instead, that shows the same value as %.0f for me, for this example.

Mike Miller <mtmiller>
Project Administrator
Tue 24 Apr 2012 04:14:26 AM UTC, original submission:

Hi All,

Bug in x64:
octave:31> (sprintf("%.0f",time*1e6))
ans = 1335236688634985
octave:32> (sprintf("%d",time*1e6))
ans = 83564835
debian stable Installed: 3.2.4-8

Anonymous

 

(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 jwe (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by None (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 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 03 Jan 2014 08:17:48 PM UTCjweStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Tue 24 Apr 2012 11:51:51 AM UTCjwePriority5 - Normal=>3 - Low
      Open/ClosedClosed=>Open
    Tue 24 Apr 2012 11:51:29 AM UTCjweItem GroupIncorrect Result=>Matlab Compatibility
      StatusInvalid=>Confirmed
    Tue 24 Apr 2012 11:23:54 AM UTCmtmillerStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1