octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #37903] difference between int32(-44) and -44


From: Mike Miller
Subject: [Octave-bug-tracker] [bug #37903] difference between int32(-44) and -44
Date: Tue, 06 Aug 2013 03:04:28 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36

Update of bug #37903 (project octave):

                Category:             Interpreter => Documentation          
              Item Group:    Matlab Compatibility => Documentation          
                  Status:                    None => Need Info              

    _______________________________________________________

Follow-up 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)


In general most integer matrices are created by casting existing matrices to
integers. The following example shows how to cast a matrix into 32 bit
integers.

     float = rand (2, 2)
          ⇒ float = 0.37569   0.92982
                    0.11962   0.50876
     integer = int32 (float)
          ⇒ integer = 0  1
                      0  1

As can be seen, floating point values are rounded to the nearest integer when
converted.


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


When doing integer division Octave will round the result to the nearest
integer. This is different from most programming languages, where the result
is often floored to the nearest integer. So, the result of int32(5) ./
int32(8) is 1.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?37903>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]