Resolve Error: Function Is Not Supported for Fixed-Point Conversion
Issue
Some functions are not supported for fixed-point conversion and could result in errors during conversion.
Possible Solutions
Isolate the Unsupported Functions
When you encounter a function that is not supported for conversion, you can temporarily leave that part of the algorithm in floating point.
The following code returns an error because the log
function is not supported for fixed-point inputs.
x = fi(rand(3),1,16,15); y = log(x)
Cast the input, x
, to a double, and then cast the output
back to a fixed-point data type.
y = fi(log(double(x)),1,16)
y = -0.2050 -0.0906 -1.2783 -0.0990 -0.4583 -0.6035 -2.0637 -2.3275 -0.0435 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
This casting allows you to continue with your conversion until you can find a replacement.
Create a Replacement Function
You can replace the unsupported function with an alternative that is supported for fixed-point conversion.
Lookup Table Approximation — You can replace many functions that are not supported for fixed-point conversion with a lookup table. For an example, see Implement Fixed-Point Log2 Using Lookup Table.
Polynomial Approximation — You can approximate the results of a function that is not supported for fixed-point with a polynomial approximation.
User-Authored Function — You can write your own function that supports fixed-point inputs. For example, using the
mod
function, which does support fixed-point inputs, you can write your own version of therem
function, which does not support fixed-point inputs.