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 Dec 7 16:01:39 2012  
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Inaccurate Result
Status: InvalidAssigned to: None
Originator Name: Michael GodfreyOpen/Closed: Closed
Release: devOperating System: Any

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

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


Wed Feb 27 16:05:35 2013, comment #3:

Yes. Close this.

But see bug #38423


Michael Godfrey <godfrey>
Project Member
Wed Feb 27 15:59:10 2013, 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 Dec 12 16:07:30 2012, 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 Dec 7 16:01:39 2012, 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 File(s):

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

    Date Changed By Updated Field Previous Value => Replaced By
    Wed Feb 27 16:52:00 2013rik5StatusNeed Info=>Invalid
    Wed Feb 27 15:59:10 2013rik5StatusNone=>Need Info

    Back to the top

    Powered by Savane 3.1-cleanup1