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: 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 27 Feb 2013 04:05:35 PM UTC, comment #3:

Yes. Close this.

But see bug #38423


Michael Godfrey <godfrey>
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>
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>


(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 27 Feb 2013 04:52:00 PM UTCrik5StatusNeed Info=>Invalid
    Wed 27 Feb 2013 03:59:10 PM UTCrik5StatusNone=>Need Info

    Back to the top

    Powered by Savane 3.1-cleanup