castIntToFi

Cast an integer data type to equivalent fi type

Description

example

y = castIntToFi(u) casts the input variable u to an equivalent fi object when u is one of the built-in MATLAB® integer data types (int8, uint8, int16, uint16, int32, uint32, int64, uint64).

When u is not one of the built-in integer data types, the output has the same data type as the input.

Examples

collapse all

Use the castIntToFi and cast64BitIntToFi functions to cast integer data types in your code to equivalent fi objects.

Create a variable with a signed 16-bit integer data type. Cast the variable to an equivalent fi object using the castIntToFi function.

u = int16(25);
y1 = castIntToFi(u)
y1 = 

    25

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

The output fi object has the same word length and signedness as the input, and zero fraction length.

The cast64BitIntToFi function casts only 64-bit integer data types to an equivalent fi object. All other input data types retain their data type.

In this example, because the input is not an int64 or uint64 data type, the output remains an int16.

y2 = cast64BitIntToFi(u)
y2 =

  int16

   25

When you pass an int64 into the cast64BitIntToFi function, the output is a fi object with a 64-bit word length and zero fraction length.

u = int64(25);
y3 = castIntToFi(u)
y3 = 

    25

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

Input Arguments

collapse all

Numeric input array, specified as a scalar, vector, matrix, or multidimensional array.

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

Output Arguments

collapse all

Numeric output, returned as a scalar, vector, matrix, or multidimensional array with the same value and dimensions as the input.

When the data type of u is an integer type, the output is a fi object with the same word length and signedness as the input, and a fraction length of zero. Otherwise, the output has the same data type as the input.

Introduced in R2020a