Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Одиноков / МиИПиС_асп_13г / MATLAB_R2013a_Выбор.doc
Скачиваний:
32
Добавлен:
15.04.2015
Размер:
4.03 Mб
Скачать

Arithmetic Operations on Integer Classes

MATLAB can perform integer arithmetic on the following types of data:

  • Integers or integer arrays of the same integer data type. This yields a result that has the same data type as the operands:

x = uint32([132 347 528]) .* uint32(75);

class(x)

ans =

uint32

  • Integers or integer arrays and scalar double-precision floating-point numbers. This yields a result that has the same data type as the integer operands:

x = uint32([132 347 528]) .* 75.49;

class(x)

ans =

uint32

For all binary operations in which one operand is an array of integer data type (except 64-bit integers) and the other is a scalar double, MATLAB computes the operation using elementwise double-precision arithmetic, and then converts the result back to the original integer data type. For binary operations involving a 64-bit integer array and a scalar double, MATLAB computes the operation as if 80-bit extended-precision arithmetic were used, to prevent loss of precision.

For a list of the operations that support integer classes, see Nondouble Data Type Support (R2013a>MATLAB>Language Fundamentals>

Operators and Elementary Operations>Arithmetic>Arithmetic Operators + - * / \ ^ ') in the arithmetic operators reference page.

Largest and Smallest Values for Integer Classes

For each integer data type, there is a largest and smallest number that you can represent with that type. The table shown under Integers (R2013a>MATLAB>Language Fundamentals>Data Types>Numeric Types) lists the largest and smallest values for each integer data type in the "Range of Values" column.

You can also obtain these values with the intmax and intmin functions:

intmax('int8') % Или intmax int8. intmin('int8') % Или intmin int8.

ans = ans =

127 -128

If you convert a number that is larger than the maximum value of an integer data type to that type, MATLAB sets it to the maximum value. Similarly, if you convert a number that is smaller than the minimum value of the integer data type, MATLAB sets it to the minimum value. For example,

x = int8(300) x = int8(-300)

x = x =

127 -128

Also, when the result of an arithmetic operation involving integers exceeds the maximum (or minimum) value of the data type, MATLAB sets it to the maximum (or minimum) value:

x = int8(100) * 3 x = int8(-100) * 3

x = x =

127 -128

Integer Functions

See Integer Functions (R2013a>MATLAB>Language Fundamentals>Data Types>Numeric Types>Function Summary) for a list of functions most commonly used with integers in MATLAB.

  • R2013a>MATLAB>Language Fundamentals>Data Types>Numeric Types

  • Floating-Point Numbers

On this page…

Double-Precision Floating Point

Single-Precision Floating Point

Creating Floating-Point Data

Arithmetic Operations on Floating-Point Numbers

Largest and Smallest Values for Floating-Point Classes

Accuracy of Floating-Point Data

Avoiding Common Problems with Floating-Point Arithmetic

Floating-Point Functions

References

MATLAB® represents floating-point numbers in either double-precision or single-precision format. The default is double precision, but you can make any number single precision with a simple conversion function.