Quantcast

Documentation Center

  • Trial Software
  • Product Updates

divide

Divide two objects

Syntax

c = divide(T,a,b)

Description

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 fixed-point 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® 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. See Data Type Propagation Rules.

If a and b are both MATLAB built-in doubles, then c is the floating-point quotient a./b, and numerictype T is ignored.

    Note:   The divide function is not currently supported for [Slope Bias] signals.

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 general, these rules can be summarized as "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 bData Type of numerictype object TData Type of Output c

Built-in double

Built-in double

Any

Built-in double

fi Fixed

fi Fixed

fi Fixed

Data type of numerictype object T

fi Fixed

fi Fixed

fi double

fi double

fi Fixed

fi Fixed

fi single

fi single

fi Fixed

fi Fixed

fi ScaledDouble

fi ScaledDouble with properties of numerictype object T

fi double

fi double

fi Fixed

fi double

fi double

fi double

fi double

fi double

fi double

fi double

fi single

fi single

fi double

fi double

fi ScaledDouble

fi double

fi single

fi single

fi Fixed

fi single

fi single

fi single

fi double

fi double

fi single

fi single

fi single

fi single

fi single

fi single

fi ScaledDouble

fi single

fi ScaledDouble

fi ScaledDouble

fi Fixed

fi ScaledDouble with properties of numerictype object T

fi ScaledDouble

fi ScaledDouble

fi double

fi double

fi ScaledDouble

fi ScaledDouble

fi single

fi single

fi ScaledDouble

fi ScaledDouble

fi ScaledDouble

fi ScaledDouble with properties of numerictype object T

Examples

This example highlights the precision of the fi divide function.

First, 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 double-precision floating-point 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 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 =

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 double-precision floating-point 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

See Also

| | | | | | | |

Was this topic helpful?