# divide

Divide two `fi` objects

## Syntax

``c = divide(T,a,b)``

## Description

example

````c = divide(T,a,b)` performs division on the elements of `a` by the elements of `b`. The result `c` has the numeric type specified by `numerictype` object `T`.```

## Examples

collapse all

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

collapse all

Numeric type of the output, specified as a `numerictype` object.

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

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

collapse all

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

collapse all

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 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`

If either input `a` or `b` is of type `fi` `ScaledDouble`, then output `c`is of type `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`

If either input `a` or `b` is of type `fi` `ScaledDouble`, then output `c` is of type `fi` `ScaledDouble` with properties of `numerictype` object `T`.

## Version History

Introduced before R2006a

expand all

Behavior changed in R2022a