Divide two objects
c = divide(T,a,b)
c = divide(T,a,b)
performs division on
the elements of a
by the elements of b
.
The result c
has the numerictype
object T
.
If a
and b
are both fi
objects, c
has
the same fimath
object as a
.
If c
has a fi
Fixed
data
type, and any one of the inputs have fi
floating
point data types, then the fi
floating point is
converted into a fixedpoint value. Intermediate quantities are calculated
using the fimath
object of a
.
See Data Type Propagation Rules.
a
and b
must have the
same dimensions unless one is a scalar. If either a
or b
is
scalar, then c
has the dimensions of the nonscalar
object.
If either a
or b
is a fi
object,
and the other is a MATLAB^{®} builtin numeric type, then the builtin
object is cast to the word length of the fi
object,
preserving bestprecision fraction length. Intermediate quantities
are calculated using the fimath
object of the input fi
object.
See Data Type Propagation Rules.
If a
and b
are both MATLAB builtin
doubles, then c
is the floatingpoint quotient a./b
,
and numerictype
T
is ignored.
The divide
function is not currently supported
for [Slope Bias] signals.
For syntaxes for which FixedPoint
Designer™ software uses
the numerictype
object T
, the divide
function
follows the data type propagation rules listed in the following table.
In general, these rules can be summarized as “floatingpoint
data types are propagated.” This allows you to write code that
can be used with both fixedpoint and floatingpoint inputs.
Data Type of Input fi Objects a and b  Data Type of numerictype object T  Data Type of Output c  

Builtin  Builtin  Any  Builtin 


 Data type of 
































 fi single 












 If either input 










 If either input 
This example highlights the precision of the fi
divide
function.
First, create an unsigned fi
object with
an 80bit word length and 2^83 scaling, which puts the leading 1
of the representation into the most significant bit. Initialize the
object with doubleprecision floatingpoint value 0.1, and examine
the binary representation:
P = ... fipref('NumberDisplay','bin',... 'NumericTypeDisplay','short',... 'FimathDisplay','none'); a = fi(0.1, false, 80, 83) a = 11001100110011001100110011001100110011001100110011010000 000000000000000000000000 u80,83
Notice that the infinite repeating representation is truncated after 52 bits, because the mantissa of an IEEE^{®} standard doubleprecision floatingpoint number has 52 bits.
Contrast the above to calculating 1/10 in fixedpoint arithmetic with the quotient set to the same numeric type as before:
T = numerictype('Signed',false,'WordLength',80,... 'FractionLength',83); a = fi(1); b = fi(10); c = divide(T,a,b); c.bin ans = 11001100110011001100110011001100110011001100110011001100 110011001100110011001100
Notice that when you use the divide
function,
the quotient is calculated to the full 80 bits, regardless of the
precision of a
and b
. Thus,
the fi
object c
represents 1/10
more precisely than IEEE standard doubleprecision floatingpoint
number can.
With 1000 bits of precision,
T = numerictype('Signed',false,'WordLength',1000,... 'FractionLength',1003); a = fi(1); b = fi(10); c = divide(T,a,b);c.bin ans =
11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 11001100110011001100110011001100110011001100110011001100 110011001100110011001100110011001100110011001100