bugGNU Octave - Bugs: bug #37882, printf('%4d', -0) prints 0

 
 

bug #37882: printf('%4d', -0) prints 0

Submitter:  Michael Godfrey <godfrey>
Submitted:  Fri 07 Dec 2012 04:01:39 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Michael Godfrey Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 27 Feb 2013 04:05:35 PM UTC, comment #3: 

Yes. Close this.

But see bug #38423

Thanks.

Michael Godfrey <godfrey>
Group Member
Wed 27 Feb 2013 03:59:10 PM UTC, comment #2: 

I think this is actually the expected behavior.

The IEEE floating point standard store numbers in a format with a signbit, mantissa, and exponent.  It is therefore possible to have a mantissa of 0 and the signbit either set or unset which leads to -/+ 0.

When you call 'printf ("%4d", -0)' you are asking the printf routine to convert a floating point number to an integer format.  The integers are stored using two's complement format and there is only a single possible zero for the integers which is +0.

If you agree that this is correct I will close this bug.

Rik <rik5>
Group administrator
Wed 12 Dec 2012 04:07:30 PM UTC, comment #1: 

But, I just noticed that
x = -0;
printf('%4g\n', x);
yields:

-0

So, should %d and %g produce different signs?

Oh, I just checked Matlab and the current Octave
behavior matches Matlab.  Ugh!

Someday it may be a useful idea to have a Section
in the Manual titled "Matlab nonsense not
provided in Octave."  This behavior is a candidate.

By the way, Octave is already different from Matlab
in that in Matlab:
x = -0;
x
yields
0

I hope that no one wants to change the behavior
of Octave to match this.

Michael Godfrey <godfrey>
Group Member
Fri 07 Dec 2012 04:01:39 PM UTC, original submission:  

Now that the handling of -0 has been much improved,
and is now not exactly matlab compatible, it would be
helpful if printf and related functions printed -0
for printf('4d', -0)  and for variables which are -0.

This is not high-priority, but it would help avoid
confusion since now:
x = -0;
x
x = -0

but printf('%4d\n', x)
yields:

  0

Michael Godfrey <godfrey>
Group Member

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2013-02-27 rik5 StatusNeed Info Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2013-02-27 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code