Main Content

floorDiv

Round the result of division toward negative infinity

Since R2021a

Description

y = floorDiv(x,d) returns the result of x/d rounded to the nearest integer value in the direction of negative infinity.

example

y = floorDiv(x,d,m) returns the result of x/d rounded to the nearest multiple of m in the direction of negative infinity.

The datatype of y is calculated such that the wordlength and fraction length are of a sufficient size to contain both the largest and smallest possible solutions given the data type of x, and the values of d and m.

example

Examples

collapse all

Perform a division operation and round to the nearest integer value in the direction of negative infinity.

floorDiv(int16(201),10)
ans = 
    20

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

Perform a division operation and round to the nearest multiple of 7 in the direction of negative infinity.

floorDiv(int16(201),10,7)
ans = 
    14

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

Define a function that uses floorDiv.

function y = floorDiv_example(x,d)
y = floorDiv(x,d);
end

Define inputs and execute the function in MATLAB®.

x = fi(pi);
d = fi(2);
y = floorDiv_example(x,d)
y = 
     1

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

To generate code for this function, the denominator d must be defined as a constant.

codegen floorDiv_example -args {x, coder.Constant(d)}
Code generation successful.

Alternatively, you can define the denominator, d, as constant in the body of the code.

function y = floorDiv10(x)
y = floorDiv(x,10);
end
x = fi(5*pi);
y = floorDiv10(x)
y = 
     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 2
        FractionLength: 0
codegen floorDiv10 -args {x}
Code generation successful.

Input Arguments

collapse all

Dividend, specified as a scalar.

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

Divisor, specified as a scalar.

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

Value to round to nearest multiple of, specified as a scalar.

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

Output Arguments

collapse all

Result of division and round to floor, returned as a scalar.

The datatype of y is calculated such that the wordlength and fraction length are of a sufficient size to contain both the largest and smallest possible solutions given the data type of x, and the values of d and m.

Extended Capabilities

Version History

Introduced in R2021a