Missing error message when using division on a uint8 type

David Bateman David.Bateman at motorola.com
Tue Aug 19 11:05:09 CDT 2008


Steen Eiler Jørgensen wrote:
> Octave version:   3.0.1
>
> Hardware:         Intel(R) Core(TM)2 Duo CPU
>                   T7500 @ 2.20GHz
>                   2.19 GHz, 1,98 GB of RAM
>                   Physical Address Extension
>
> OS:               Microsoft Windows XP
>                   Professional
>                   Version 2002
>                   Service Pack 2
>
> Description:
> -----------
>  
>     When dividing a uint8 type with e.g. an integer, the rounded result is returned.
>     In MatLab, the same operation returns an error message.
>     The problem can be worked around by using double(foo); float(foo) does not work.
>     
> Repeat-By:
> ---------
>  
>     uint8(11)/3
>     
>     will yield the result 4, which should obviously have been 3.6667.
>     
> Fix:
> ---
>
> In MatLab, the same operation results in an error message with the text:
>
> ??? Error using ==> /
>    Function '/' not defined for variables of class 'uint8'.
>
>   
No the current behavior is correct. The Matlab promotion/demotion rules 
are discussed in matlab's online manual in the section

Programming Fundamentals
Built-In Classes (Data Types)
Numeric Classes
Floating-Point Numbers
Arithmetic Operations on Floating-Point Numbers

where the text is

<quote>
*Double-Precision. *You can perform basic arithmetic operations with 
double and any of the following other classes. When one or more operands 
is an integer (scalar or array), the double operand must be a scalar. 
The result is of type double, except where noted otherwise:

    * single — The result is of type single
    * double
    * int* or uint* — The result has the same data type as the integer
      operand
    * char
    * logical

</quote>

So any arithmetic operation combining double and an integer type returns 
the integer type. Note in Matlab 2008a I see

 >> uint8(11)/3

ans =

4

So note I think you might be using an older buggy version of matlab for 
comparison.

D.


-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Bug-octave mailing list