bugGNU Octave - Bugs: bug #51252, incorrect type casting of colon...

 
 

bug #51252: incorrect type casting of colon operator ':'

Submitted by:  Xiangmin Jiao <xmjiao>
Submitted on:  Fri 16 Jun 2017 08:12:38 PM UTC  
 
Category: InterpreterSeverity: 2 - Minor
Priority: 3 - LowItem Group: Matlab Compatibility
Status: ConfirmedAssigned to: None
Originator Name: Xiangmin JiaoOpen/Closed: Open
Release: 4.2.1Operating System: Any

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 20 Jun 2017 03:45:32 PM UTC, comment #4:

Interesting. This will require a small project to implement correctly. The Range object needs to be extended to do more input validation, and it needs a new private variable which records the output class. Internally, everything can still be done with doubles but the output can be cast to the correct type whenever required.

For the time being, just casting the range to the desired type within a script file is the best solution.

Rik <rik5>
Project Administrator
Tue 20 Jun 2017 11:13:23 AM UTC, comment #3:

Output in Matlab R2016a:

Markus Mützel <mmuetzel>
Project Member
Tue 20 Jun 2017 04:38:57 AM UTC, comment #2:

What does Matlab return for

Also, what does this code return

Rik <rik5>
Project Administrator
Mon 19 Jun 2017 07:12:52 PM UTC, comment #1:

Yes, in Octave the colon expression returns a "range" object which is only implemented in terms of double values (or however the "colon" overload method of a user-defined class is defined).

If Matlab's colon expression preserves the standard type precedence of built in types, then some redesign work is needed in Octave to make this compatible.

OTOH it's very easy to write

instead.

Mike Miller <mtmiller>
Project Administrator
Fri 16 Jun 2017 08:12:38 PM UTC, original submission:

In Octave 3.8.1, 4.0.2 and 4.2.1, the ':' operator returns incorrect data types:
```
class( int32(1) : int32 (10))
```

It returns double. However, the expected answer is int32.

Similarly,
```
class( int32(1) : 10)
class( int32(1) : int32(1), int32(10))
class( single(1) : 10)
class( single(1) : single(1), single(10))
```

all return double, but the first two should return int32, and the last two should return single. I have observed this behavior in Ocatve 3.8.1, 4.0.2 and 4.2.1.

This is incompatible with MATLAB. It is also incompatible with the precedence of data types in Octave for other operators. For example,
```
1 + int32(2)
```
returns an int32, so int32 takes precedence over double.

Therefore, it is clearly a bug.

Xiangmin Jiao <xmjiao>

 

(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 mmuetzel (Posted a comment)
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by xmjiao (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 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 20 Jun 2017 03:45:32 PM UTCrik5StatusNone=>Confirmed
    Mon 19 Jun 2017 07:12:52 PM UTCmtmillerCategoryOctave Function=>Interpreter
      Severity3 - Normal=>2 - Minor
      Priority5 - Normal=>3 - Low
      Item GroupIncorrect Result=>Matlab Compatibility

    Back to the top


    Powered by Savane 3.1-cleanup1