Main Content

Set fixed-point math settings

`F = fimath`

creates a `fimath`

object with the
default `fimath`

property settings.

`F = fimath(`

specifies the
properties of a `Name,Value`

)`fimath`

object by using one or more name-value pair
arguments. All properties not specified in the constructor use default values.

This example shows how to create a `fimath`

object with the default property settings.

F = fimath

F = RoundingMethod: Nearest OverflowAction: Saturate ProductMode: FullPrecision SumMode: FullPrecision

Set the properties of a `fimath`

object at the time of object creation by using name-value pairs. For example, set the overflow action to saturate and the rounding method to convergent.

F = fimath('OverflowAction','Saturate','RoundingMethod','Convergent')

F = RoundingMethod: Convergent OverflowAction: Saturate ProductMode: FullPrecision SumMode: FullPrecision

Specify optional
comma-separated pairs of `Name,Value`

arguments. `Name`

is
the argument name and `Value`

is the corresponding value.
`Name`

must appear inside quotes. You can specify several name and value
pair arguments in any order as
`Name1,Value1,...,NameN,ValueN`

.

```
F =
fimath('OverflowAction','Saturate','RoundingMethod','Floor')
```

`CastBeforeSum`

— Whether both operands are cast to the sum data type before addition`false`

or `0`

(default) | `true`

or `1`

Whether both operands are cast to the sum data type before addition, specified as
a numeric or logical `1`

(`true`

) or
`0`

(`false`

).

**Note**

This property is hidden when the `SumMode`

is set to
`FullPrecision`

.

**Example: **`F = fimath('CastBeforeSum',true)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

| `logical`

`MaxProductWordLength`

— Maximum allowable word length for the product data type`65535`

(default) | positive integerMaximum allowable word length for the product data type, specified as a positive integer.

**Example: **`F = fimath('MaxProductWordLength',16)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`MaxSumWordLength`

— Maximum allowable word length for sum data type65535 (default) | positive integer

Maximum allowable word length for the sum data type, specified as a positive integer.

**Example: **`F = fimath('MaxSumWordLength',16)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`OverflowAction`

— Action to take on overflow`'Saturate'`

(default) | `'Wrap'`

Action to take on overflow, specified as one of these values:

`'Saturate'`

– Saturate to the maximum or minimum value of the fixed-point range on overflow.`'Wrap'`

– Wrap on overflow. This mode is also known as two's complement overflow.

**Example: **`F = fimath('OverflowAction','Wrap')`

**Data Types: **`char`

`ProductBias`

— Bias of product data type`0`

(default) | floating-point numberBias of the product data type, specified as a floating-point number.

**Example: **`F = fimath('ProductBias',1)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`ProductFixedExponent`

— Fixed exponent of product data type`-30`

(default) | nonzero integerFixed exponent of the product data type, specified as a nonzero integer.

**Note**

The `ProductFractionLength`

is the negative of the
`ProductFixedExponent`

. Changing one property changes the
other.

**Example: **`F = fimath('ProductFixedExponent',-20)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`ProductFractionLength`

— Fraction length of product data type`30`

(default) | nonzero integerFraction length, in bits, of the product data type, specified as a nonzero integer.

**Note**

The `ProductFractionLength`

is the negative of the
`ProductFixedExponent`

. Changing one property changes the
other.

**Example: **`F = fimath('ProductFractionLength',20)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`ProductMode`

— How product data type is determined`'FullPrecision'`

(default) | `'KeepLSB'`

| `'KeepMSB'`

| `'SpecifyPrecision'`

How the product data type is determined, specified as one of these values:

`'FullPrecision'`

– The full precision of the result is kept.`'KeepLSB'`

– Keep the least significant bits. Specify the product word length. The fraction length is set to maintain the least significant bits of the product.`'KeepMSB'`

– Keep the most significant bits. Specify the product word length. The fraction length is set to maintain the most significant bits of the product.`'SpecifyPrecision'`

– Specify the word and fraction lengths or slope and bias of the product.

**Example: **`F = fimath('ProductMode','KeepLSB')`

**Data Types: **`char`

`ProductSlope`

— Slope of product data type`9.3132e-10`

(default) | finite, positive floating-point numberSlope of the product data type, specified as a finite, positive floating-point number.

**Note**

$$ProductSlope=ProductSlopeAdjustmentFactor\times {2}^{ProductFixedExponent}$$

Changing one of these properties affects the others.

**Example: **`F = fimath('ProductSlope',9.3132e-10)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`ProductSlopeAdjustmentFactor`

— Slope adjustment factor of the product data type`1`

(default) | floating-point number greater than or equal to 1 and less than 2Slope adjustment factor of the product data type, specified as a floating-point number greater than or equal to 1 and less than 2.

**Note**

$$ProductSlope=ProductSlopeAdjustmentFactor\times {2}^{ProductFixedExponent}$$

Changing one of these properties affects the others.

**Example: **```
F =
fimath('ProductSlopeAdjustmentFactor',1)
```

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`ProductWordLength`

— Word length of product data type`32`

(default) | positive integerWord length, in bits, of the product data type, specified as a positive integer.

**Example: **`F = fimath('ProductWordLength',64)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`RoundingMethod`

— Rounding method to use`'Nearest'`

(default) | `'Ceiling'`

| `'Convergent'`

| `'Zero'`

| `'Floor'`

| `'Round'`

Rounding method to use, specified as one of these values:

`'Nearest'`

– Round toward nearest. Ties round toward positive infinity.`'Ceiling'`

– Round toward positive infinity.`'Convergent'`

– Round toward nearest. Ties round to the nearest even stored integer (least biased).`'Zero'`

– Round toward zero.`'Floor'`

– Round toward negative infinity.`'Round'`

– Round toward nearest. Ties round toward negative infinity for negative numbers, and toward positive infinity for positive numbers.

**Example: **```
F =
fimath('RoundingMethod','Convergent')
```

**Data Types: **`char`

`SumBias`

— Bias of sum data type`0`

(default) | floating-point numberBias of the sum data type, specified as a floating-point number.

**Example: **`F = fimath('SumBias',0)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SumFixedExponent`

— Fixed exponent of sum data type`-30`

(default) | nonzero integerFixed exponent of the sum data type, specified as a nonzero integer.

**Note**

The `SumFractionLength`

is the negative of the
`SumFixedExponent`

. Changing one property changes the
other.

**Example: **`F = fimath('SumFixedExponent',-20)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SumFractionLength`

— Fraction length of sum data type`30`

(default) | nonzero integerFraction length, in bits, of the sum data type, specified as a nonzero integer.

**Note**

The `SumFractionLength`

is the negative of the
`SumFixedExponent`

. Changing one property changes the
other.

**Example: **`F = fimath('SumFractionLength',20)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SumMode`

— How the sum data type is determined`'FullPrecision'`

(default) | `'KeepLSB'`

| `'KeepMSB'`

| `'SpecifyPrecision'`

How the sum data type is determined, specified as one of these values:

`'FullPrecision'`

– The full precision of the result is kept.`'KeepLSB'`

– Keep least significant bits. Specify the sum data type word length. The fraction length is set to maintain the least significant bits of the sum.`'KeepMSB'`

– Keep most significant bits. Specify the sum data type word length. The fraction length is set to maintain the most significant bits of the sum and no more fractional bits than necessary.`'SpecifyPrecision'`

– Specify the word and fraction lengths or slope and bias of the sum data type.

**Example: **`F = fimath('SumMode','KeepLSB')`

**Data Types: **`char`

`SumSlope`

— Slope of sum data type`9.3132e-10`

(default) | floating-point numberSlope of the sum data type, specified as a floating-point number.

**Note**

$$SumSlope=SumSlopeAdjustmentFactor\times {2}^{SumFixedExponent}$$

Changing one of these properties affects the others.

**Example: **`F = fimath('SumSlope',9.3132e-10)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SumSlopeAdjustmentFactor`

— Slope adjustment factor of the sum data type`1`

(default) | floating-point number greater than or equal to 1 and less than 2Slope adjustment factor of the sum data type, specified as a floating-point number greater than or equal to 1 and less than 2.

**Note**

$$SumSlope=SumSlopeAdjustmentFactor\times {2}^{SumFixedExponent}$$

Changing one of these properties affects the others.

**Example: **`F = fimath('SumSlopeAdjustmentFactor',1)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`SumWordLength`

— Word length of sum data type`32`

(default) | positive integerWord length, in bits, of the sum data type, specified as a positive integer.

**Example: **`F = fimath('SumWordLength',64)`

**Data Types: **`single`

| `double`

| `int8`

| `int16`

| `int32`

| `int64`

| `uint8`

| `uint16`

| `uint32`

| `uint64`

`fi`

, `fimath`

, and `numerictype`

objects not supportedIn previous releases, inexact property names for `fi`

,
`fimath`

, and `numerictype`

objects would result in a
warning. In R2021a, support for inexact property names was removed. Use exact property names
instead.

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

Fixed-point signals coming in to a MATLAB

^{®}Function block from Simulink^{®}are assigned a`fimath`

object. You define this object in the MATLAB Function block dialog in the Model Explorer.Use to create

`fimath`

objects in the generated code.If the

`ProductMode`

property of the`fimath`

object is set to anything other than`FullPrecision`

, the`ProductWordLength`

and`ProductFractionLength`

properties must be constant.If the

`SumMode`

property of the`fimath`

object is set to anything other than`FullPrecision`

, the`SumWordLength`

and`SumFractionLength`

properties must be constant.

Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

`fi`

| `fipref`

| `globalfimath`

| `numerictype`

| `quantizer`

| `removefimath`

| `setfimath`

You have a modified version of this example. Do you want to open this example with your edits?

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.

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: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

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