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: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: NoneAssigned to: None
Originator Name: godfreyOpen/Closed: Open
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.

 

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>
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>

 

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

Attach File(s):
   
   
Comment:
   

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 jwe (Posted a comment)
  • -unavailable- added by godfrey (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup