Documentation

mod

Modulus after division for fi objects

Syntax

M = mod(X,Y)

Description

M = mod(X,Y) if Y ~= 0, returns X-n.*Y, where n = floor(X./Y). The inputs X and Y must be real arrays of the same size, or either can be a real scalar. For fixed-point or integer input arguments, the output data type is the aggregate type of both input signedness, word lengths, and fraction lengths. For floating-point input arguments, the output data type is the same as the inputs.

The mod function ignores and discards any fimath attached to the inputs. The output is always associated with the default fimath.

Note

The combination of fixed-point and floating-point inputs is not currently supported.

Input Arguments

X

Integer, fixed-point, or floating-point array, or real scalar.

Y

Array of the same size as X, or real scalar.

Output Arguments

M

Result of modulus operation. If both inputs X and Y are floating-point, then the data type of M is the same as the inputs. If either input X or Y is fixed-point, then the data type of M is the aggregate numerictype. This value equals that of fixed.aggregateType(X,Y).

Examples

Calculate the mod of two fi objects.

% 7-bit signed fixed-point object
x = fi(-3,1,7,0);
% 15-bit signed fixed-point object
y = fi(2,1,15,0);
M1 = mod(x,y)
M1 =
 
     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 15
        FractionLength: 0
M2 = mod(y,x)
M2 =
 
    -1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 15
        FractionLength: 0

Convert the fi inputs in the previous example to double type, and calculate the mod.

Mf1 = mod(double(x),double(y))
Mf1 =

     1
Mf2 = mod(double(y),double(x))
Mf2 =

    -1

Introduced in R2011b

Was this topic helpful?