divide
Divide two fi
objects
Syntax
Description
Examples
Divide Two fi Objects
This example shows how to control the precision of the divide
function.
Create an unsigned fi
object with an 80-bit word length and 2^-83 scaling, which puts the leading 1 of the representation into the most significant bit. Initialize the object with value 0.1, and examine the binary representation.
P = fipref('NumberDisplay', 'bin',... 'NumericTypeDisplay', 'short',... 'FimathDisplay', 'none'); a = fi(0.1, 0, 80, 83)
a = 11001100110011001100110011001100110011001100110011010000000000000000000000000000 numerictype(0,80,83)
Notice that the infinite repeating representation is truncated after 52 bits, because the mantissa of an IEEE® standard double-precision floating-point number has 52 bits.
Contrast the above to calculating 1/10 in fixed-point 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 = '11001100110011001100110011001100110011001100110011001100110011001100110011001101'
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 a IEEE® standard double-precision floating-point number can.
Input Arguments
T
— Numeric type of the output
numerictype
object
Numeric type of the output, specified as a numerictype
object.
a
— Numerator
scalar | vector | matrix | multidimensional array
Numerator, specified as a scalar, vector, matrix, or multidimensional array.
Inputs a
and b
must either be the same size or
have sizes that are compatible. For more information, see Compatible Array Sizes for Basic Operations.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| fi
Complex Number Support: Yes
b
— Denominator
scalar | vector | matrix | multidimensional array
Denominator, specified as a real scalar, vector, matrix, or multidimensional array.
Inputs a
and b
must either be the same size or
have sizes that are compatible. For more information, see Compatible Array Sizes for Basic Operations.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| fi
Complex Number Support: Yes
Output Arguments
c
— Quotient
scalar | vector | matrix | multidimensional array
Solution, returned as a scalar, vector, matrix, or multidimensional array.
The size of c
is determined by implicit expansion of the
dimensions of a
and b
. For more information, see
Compatible Array Sizes for Basic Operations.
Algorithms
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
fixed-point value. Intermediate quantities are calculated using the fimath
object of a
.
If either a
or b
is a fi
object,
and the other is a MATLAB® built-in numeric type, then the built-in object is cast to the word length of
the fi
object, preserving best-precision fraction length. Intermediate
quantities are calculated using the fimath
object of the input
fi
object.
If a
and b
are both MATLAB built-in doubles, then c
is the floating-point quotient
a./b
, and numerictype
T
is ignored.
Data Type Propagation Rules
For syntaxes for which Fixed-Point Designer™ software uses the numerictype
object T
,
the divide
function follows the data type propagation rules listed in the
following table. In most cases, floating-point data types are propagated. This allows you to
write code that can be used with both fixed-point and floating-point inputs.
Data Type of Input fi Objects a and b | Data Type of numerictype Object T | Data Type of Output c | |
---|---|---|---|
Built-in | Built-in | Any | Built-in |
|
|
| Data type of |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| fi
single |
|
|
|
|
|
|
|
|
|
|
|
|
| If either input |
|
|
|
|
|
|
|
|
|
|
| If either input |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Any non-
fi
input must be constant; that is, its value must be known at compile time so that it can be cast to afi
object.Complex and imaginary divisors are not supported.
Code generation does not support the syntax
T.divide(a,b)
.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
For HDL Code generation, the divisor must be a constant and a power of two.
Non-
fi
inputs must be constant; that is, their values must be known at compile time so that they can be cast tofi
objects.Complex and imaginary divisors are not supported.
Code generation in MATLAB does not support the syntax
T.divide(a,b)
.
Version History
Introduced before R2006aR2022a: Implicit expansion change affects arguments for operators
Starting in R2022a with the addition of implicit expansion for fi
divide
, some combinations of arguments for basic operations that
previously returned errors now produce results.
If your code uses element-wise operators and relies on the errors that MATLAB previously returned for mismatched sizes, particularly within a
try/catch
block, then your code might no longer catch those
errors.
For more information on the required input sizes for basic array operations, see Compatible Array Sizes for Basic Operations.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)