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


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

Submitted by:  Michael Godfrey <godfrey>
Submitted on:  Fri 07 Dec 2012 04:01:39 PM UTC  
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid Assigned to:  None
Originator Name:  Michael Godfrey Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment(Rich Markup)

You are not logged in

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


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

Yes. Close this.

But see bug #38423


Michael Godfrey <godfrey>
Project 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>
Project Administrator
Wed 12 Dec 2012 04:07:30 PM UTC, comment #1:

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


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;

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

Michael Godfrey <godfrey>
Project 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 = -0

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


Michael Godfrey <godfrey>
Project Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

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)

    Do you think this task is very important?
    If so, you can 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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    Wed 27 Feb 2013 04:52:00 PM UTC rik5 StatusNeed Info => Invalid
        Open/ClosedOpen => Closed
    Wed 27 Feb 2013 03:59:10 PM UTC rik5 StatusNone => Need Info

    Back to the top

    Powered by Savane 3.3