Skip to Main Content Skip to Search
Product 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 fixed-point inputs, the word length of the internally computed aggregate fixed-point output data type cannot exceed 32 bits. For floating-point input arguments, the output data type is the same as the inputs.

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

See Also

fixed.aggregateType | mod

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS