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

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

[Octave-bug-tracker] [bug #53128] Warn about implicit casts from int to


From: Benjamin Buch
Subject: [Octave-bug-tracker] [bug #53128] Warn about implicit casts from int to double
Date: Mon, 12 Feb 2018 05:03:00 -0500 (EST)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0

URL:
  <http://savannah.gnu.org/bugs/?53128>

                 Summary: Warn about implicit casts from int to double
                 Project: GNU Octave
            Submitted by: bebuch
            Submitted on: Mon 12 Feb 2018 10:02:58 AM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Feature Request
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.0.0
        Operating System: Any

    _______________________________________________________

Details:

I have a source similar to this:


img = uint8(ones([600, 800]));
factor = 1.7;

img_size = size(img);
result = zeros(img_size); % type is double

for c = 1:img_size(2)
for r = 1:img_size(1)
result(r,c) = img(r,c) * factor;
end
end


The result is, that all values in result are of type double and have value 2.
This is because the multiplication result is of type uint8. So far so good,
but within the assignment the result is implicit casted to double. If you
don't expect the multiplication result is of type int, this is an bug, that is
very very hard to find.

No variable indicates that an integer multiplication has taken place. Most of
the Octave users around me are not aware that there are any integers in Octave
at all! Those who have experience with other programming languages will not
expect that a binary operation of int and double will have an int as the
result.

While in most other programming languages the implicit conversion from double
to int is a bug, in Octave it is the other way round. Most of the implicit
conversions from int to double take place with faulty code. Please issue a
warning if an implicit conversion from int to double takes place.

I have colleagues who have spent hours and sometimes several days and with the
help of other colleagues are desperate for such mistakes.

(Same request to Matlab with Case Number 02956888)




    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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