bugGNU Octave - Bugs: bug #37903, difference between int32(-44) and...


bug #37903: difference between int32(-44) and -44

Submitted by:  Michael Godfrey <godfrey>
Submitted on:  Tue 11 Dec 2012 08:58:08 PM UTC  
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  Wont Fix Assigned to:  None
Originator Name:  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.


Thu 27 Mar 2014 02:54:12 AM UTC, comment #4:

No progress on this bug in over a year, the excerpts from the manual that I mentioned seem pretty clear on the topic to me, so I'm not sure what needs to be added to the manual. Closing, feel free to reopen or report as a new bug if this still needs work.

Mike Miller <mtmiller>
Project Administrator
Tue 06 Aug 2013 03:04:27 AM UTC, comment #3:

I think it's guaranteed that we do need to retain Matlab compatibility for the way values are rounded when casting a floating point value to an integer type. I'm relabeling this to reflect the last comment that the documentation should be corrected.

Can you suggest what should be added or propose a patch to the manual?

For reference, here is what the manual has to say on the issue, I think it's pretty clear (from http://www.gnu.org/software/octave/doc/interpreter/Integer-Data-Types.html)

And on the issue of integer division (from http://www.gnu.org/software/octave/doc/interpreter/Integer-Arithmetic.html)

Mike Miller <mtmiller>
Project Administrator
Tue 11 Dec 2012 10:10:28 PM UTC, comment #2:

John said:
"I don't see this as a problem with floor as much as the confusing way that
integers work in Matlab and that we have to conform to for compatibility."

I agree that Matlab is weird and the problem can be
considered to be with integers. But, it definitely leads
to confusion.

Is it really necessary to be Matlab compatible on this issue?

If so, the documentation needs to be corrected to reflect
the behavior. I find it hard to explain in terms ofther
than "Matlab does it that way."

Michael Godfrey <godfrey>
Project Member
Tue 11 Dec 2012 09:58:29 PM UTC, comment #1:

I don't see this as a problem with floor as much as the confusing way that integers work in Matlab and that we have to conform to for compatibility.

It looks to me as though int32(-46)/10 is -5 because the result of the division is rounded to nearest instead of just truncating the fractional part. Note that it is true whether you use in32(-46)/10, which is division by a double, or int32(-46)/int32(10), which is division of two int32 values.

John W. Eaton <jwe>
Project Administrator
Tue 11 Dec 2012 08:58:08 PM UTC, original submission:

The Manual says floor(x) returns the largest integer not greater than x. For x type double this is what it does. But for x int32
floor(int32(-44)/10) is -4. floor(-44/10) is -5. And, even worse, floor(int32(-46)/10) is -5. This is not
consistent with the Manual or help, but it is what Matlab does!!

So, is this a documentation problem, or could
it behave in a more reasonable way despite Matlab?

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

    Date Changed by Updated Field Previous Value => Replaced by
    Thu 27 Mar 2014 02:54:12 AM UTC mtmiller StatusNeed Info => Wont Fix
        Open/ClosedOpen => Closed
    Tue 06 Aug 2013 03:04:27 AM UTC mtmiller CategoryInterpreter => Documentation
        Item GroupMatlab Compatibility => Documentation
        StatusNone => Need Info

    Back to the top

    Powered by Savane 3.1-cleanup1