Main Content

Mapping of Different Rounding and Overflow Methods from MATLAB to SystemC

The specified fixed-point data types in MATLAB® code are converted to SystemC fixed-point data types during code generation.

The tables show the mapping of different MATLAB fixed-point rounding and overflow methods to their equivalent SystemC methods.

Rounding Methods

MATLAB Fixed-Point Rounding MethodsDescriptionEquivalent SystemC Fixed-Point Rounding Methods

Nearest

(default for MATLAB)

Rounds to the nearest representable number.

SC_RND

Zero

Rounds to the nearest representable number in the direction of zero.

SC_TRN_ZERO

Floor

Rounds to the nearest representable number in the direction of negative infinity.

Equivalent to two's complement truncation.

SC_TRN

(default for SystemC)

Round

Rounds to the nearest representable number.

SC_RND_INF

Convergent

Rounds to the nearest representable number.

SC_RND_CONV

Note

The ceiling rounding method is not supported for SystemC code generation.

Overflow Methods

MATLAB Fixed-Point Overflow MethodsDescriptionEquivalent SystemC Fixed-Point Overflow Methods

Saturate

(default for MATLAB)

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

SC_SAT

Wrap

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

SC_WRAP

(default for SystemC)

The rounding and overflow methods are represented as typecasts on expressions in the generated SystemC code.

For example, consider the MATLAB function exampleFun and the generated SystemC code to understand the conversion of rounding and overflow methods.

MATLAB Code

function y = exampleFun(a, b)
    y = fi(a + b, 1, 5, 2, fimath('RoundingMethod','Nearest','OverflowAction','Saturate'));
end

Generated SystemC Code

class exampleFunClass
{
    public:
    sc_fixed<5,3> exampleFun(sc_fixed<7,3> a, sc_fixed<7,3> b)
    {
        return (sc_fixed<5,3,SC_RND,SC_SAT>)((sc_fixed<8,4>)a + (sc_fixed<8,4>)b);
    }
};