Use castIntToFi to handle both fi and integer types.
If you want your code to work with both built-in integer types and fi objects, you can use the castIntToFi utility. This function converts integer types to equivalent fi objects, and passes through fi objects unchanged—eliminating the need for explicit branching.
x = uint8(15); % Built-in integer type
y = fi(3, 0, 8, 0); % fi object
% Use castIntToFi to ensure both are fi objects
x_fi = castIntToFi(x);
y_fi = castIntToFi(y);
result = bitconcat(x_fi, y_fi); % Now works regardless of original type
- If the input is already a fi object, castIntToFi returns it unchanged.
- If the input is an integer type, it creates a fi object with the same value and numerictype.