Contents

sfrac

Create Simulink.NumericType object describing signed fractional data type

Syntax

a = sfrac(WordLength)
a = sfrac(WordLength, GuardBits)

Description

sfrac(WordLength) returns a Simulink.NumericType object that describes the data type of a signed fractional data type with a word size given by WordLength.

sfrac(WordLength, GuardBits) returns a Simulink.NumericType object that describes the data type of a signed fractional number. The total word size is given by WordLength with GuardBits bits located to the left of the binary point.

The most significant (leftmost) bit is the sign bit. The default binary point for this data type is assumed to lie immediately to the right of the sign bit. If guard bits are specified, they lie to the left of the binary point and to right of the sign bit. For example, the structure for an 8-bit signed fractional data type with 4 guard bits is:

    Note:   sfrac is a legacy function. In new code, use fixdt instead. In existing code, replace sfrac(WordLength,GuardBits) with fixdt(1,WordLength,(WordLength-1-GuardBits)) and sfrac(WordLength) with fixdt(1,WordLength,(WordLength-1)).

Examples

Define an 8-bit signed fractional data type with 4 guard bits. Note that the range of this data type is -24 = -16 to (1 - 2(1 - 8)).24 = 15.875.

a = sfrac(8,4)
a = 

  NumericType with properties:

      DataTypeMode: 'Fixed-point: binary point scaling'
        Signedness: 'Signed'
        WordLength: 8
    FractionLength: 3
           IsAlias: 0
         DataScope: 'Auto'
        HeaderFile: ''
       Description: ''
Was this topic helpful?