Main Content

fixed.fimathLike

Return fimath object like the input

Since R2022b

Description

F = fixed.fimathLike(X) returns fimath object F with ProductMode and SumMode set to the same fixed-point arithmetic properties as the input X, where X is a fi object or numerictype object.

By default, RoundingMethod is set to 'Floor' and OverflowAction is set to 'Wrap'. For fixed-point inputs, this function supports binary-point scaling and slope-bias scaling. If X is not a fi object or numerictype object, then empty is returned.

example

F = fixed.fimathLike(X,roundingMethod) specifies the rounding method to use.

example

F = fixed.fimathLike(X,roundingMethod,overflowAction) specifies the rounding method and overflow action to use.

example

Examples

collapse all

Use fixed.fimathLike and setfimath to set the fimath fixed-point math settings to be like the input.

Define a fixed-point fi object.

X = fi(1,1,8,0)

Create a fimath object with the same fixed-point math settings as the input.

F = fixed.fimathLike(X)
F = 


        RoundingMethod: Floor
        OverflowAction: Wrap
           ProductMode: SpecifyPrecision
     ProductWordLength: 8
 ProductFractionLength: 0
               SumMode: SpecifyPrecision
         SumWordLength: 8
     SumFractionLength: 0
         CastBeforeSum: true

Apply the fixed-point math settings.

X(:) = setfimath(X,F) + 1
X = 

     2

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 8
        FractionLength: 0

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

If X is a fi object or numerictype object, then fixed.fimathLike returns a fimath object. Otherwise, fixed.fimathLike returns empty.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

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

  • 'Ceiling' — Round toward positive infinity.

  • 'Convergent' — Round toward nearest. Ties round to the nearest even stored integer (least biased).

  • 'Floor' — Round toward negative infinity.

  • 'Nearest' — Round toward nearest. Ties round toward positive infinity.

  • 'Round' — Round toward nearest. Ties round toward negative infinity for negative numbers, and toward positive infinity for positive numbers.

  • 'Zero' — Round toward zero.

Data Types: char | string

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

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

  • 'Saturate' — Saturate to the maximum or minimum value of the fixed-point range on overflow.

Data Types: char | string

Output Arguments

collapse all

Fixed-point math settings, returned as a fimath object.

If X is not a fi object or numerictype object, then fixed.fimathLike returns empty.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2022b