23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Numeric Types<br />

Arithmetic Operations on Integer Data Types<br />

<strong>MATLAB</strong> can perform integer arithmetic on the following types of data:<br />

• Integers or integer arrays of the same integer data type. This yields a<br />

result that has the same data type as the operands:<br />

x = uint32([132 347 528]) .* uint32(75);<br />

• Integers or integer arrays and scalar double-precision floating-point<br />

numbers. This yields a result that has the same data type as the integer<br />

operands:<br />

x = uint32([132 347 528]) .* 75.49;<br />

For all binary operations in which one operand is an array of integer data<br />

type and the other is a scalar double, <strong>MATLAB</strong> computes the operation using<br />

elementwise double-precision arithmetic, and then converts the result back to<br />

the original integer data type.<br />

For a list of the operations that support integer data types, see Nondouble<br />

Data Type Support in the arithmetic operators reference page.<br />

Largest and Smallest Values for Integer Data Types<br />

For each integer data type, there is a largest and smallest number that you<br />

can represent with that type. The table shownunder“Integers”onpage2-6<br />

lists the largest and smallest values for each integer data type in the “Range<br />

of Values” column.<br />

You can also obtain these values with the intmax and intmin functions:<br />

intmax('int8')<br />

intmin('int8')<br />

ans = ans =<br />

127 -128<br />

If you convert a number that is larger than the maximum value of an integer<br />

data type to that type, <strong>MATLAB</strong> sets it to the maximum value. Similarly, if<br />

you convert a number that is smaller than the minimum value of the integer<br />

data type, <strong>MATLAB</strong> sets it to the minimum value. For example,<br />

x = int8(300)<br />

x = int8(-300)<br />

2-9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!