# mod

Modulus after division for fi objects

## Description

example

m = mod(x,y) returns the modulus after division of x by y, where x is the dividend and y is the divisor. This function is often called the modulo operation, which can be expressed as m = x - floor(x./y).*y.

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 supported.

## Examples

collapse all

Calculate the mod of two fi objects.

x = fi(-3,1,7,0);
y = fi(2,1,15,0);
m1 = mod(x,y)
m2 = mod(y,x)
m1 =

1

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

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))
Mf2 = mod(double(y),double(x))
Mf1 =

1

Mf2 =

-1

## Input Arguments

collapse all

Dividend, specified as a scalar, vector, matrix, or multidimensional array. x must be a real-valued integer, fixed-point, or floating-point array, or real scalar. Numeric inputs x and y must either be the same size, or have sizes that are compatible.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Divisor, specified as a scalar, vector, matrix, or multidimensional array. y must be a real-valued integer, fixed-point, or floating-point array, or real scalar. Numeric inputs x and y must either be the same size, or have sizes that are compatible.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

## Output Arguments

collapse all

Result of modulus operation, returned as a scalar, vector, matrix, or multidimensional array.

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).

The output m is always associated with the default fimath.

## Algorithms

mod(x,y) for a fi object uses the same definition as the built-in MATLAB® mod function.

## Version History

Introduced in R2011b