0
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 element-wise
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.
Operations involving complex numbers with integer types is not supported.
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” on page 4-2 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')
ans =
int8
127
intmin('int8')
ans =
int8
-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,
4 Numeric Classes
4-4
Précédent

- 148/1450

Suivant