Main Content

numerictype

Construct an embedded.numerictype object describing fixed-point or floating-point data type

Description

example

T = numerictype creates a default numerictype object.

example

T = numerictype(s) creates a fixed-point numerictype object with unspecified scaling, a signed property value of s, and a 16-bit word length.

example

T = numerictype(s,w) creates a fixed-point numerictype object with unspecified scaling, a signed property value of s, and word length of w.

example

T = numerictype(s,w,f) creates a fixed-point numerictype object with binary point scaling, a signed property value of s, word length of w, and fraction length of f.

example

T = numerictype(s,w,slope,bias) creates a fixed-point numerictype object with slope and bias scaling, a signed property value of s, word length of w, slope, and bias.

example

T = numerictype(s,w,slopeadjustmentfactor,fixedexponent,bias) creates a fixed-point numerictype object with slope and bias scaling, a signed property value of s, word length of w, slopeadjustmentfactor, and bias.

example

T = numerictype(___,Name,Value) allows you to set properties using name-value pairs. All properties that you do not specify a value for are assigned their default values.

example

T = numerictype(T1,Name,Value) allows you to make a copy, T1, of an existing numerictype object, T, while modifying any or all of the property values.

example

T = numerictype('Double') creates a numerictype object of data type double.

example

T = numerictype('Single') creates a numerictype object of data type single.

example

T = numerictype('Boolean') creates a numerictype object of data type Boolean.

Examples

collapse all

This example shows how to create a numerictype object with default property settings.

T = numerictype
T =


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

This example shows how to create a numerictype object with the default word length and scaling by omitting the arguments for word length, w, and fraction length, f.

T = numerictype(1)
T =


          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Signed
            WordLength: 16

The object is signed, with a word length of 16 bits and unspecified scaling.

You can use the signedness argument, s, to create an unsigned numerictype object.

T = numerictype(0)
T =


          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Unsigned
            WordLength: 16

The object is has the default word length of 16 bits and unspecified scaling.

This example shows how to create a numerictype object with unspecified scaling by omitting the fraction length argument, f.

T = numerictype(1,32)
T =


          DataTypeMode: Fixed-point: unspecified scaling
            Signedness: Signed
            WordLength: 32

The object is signed, with a 32-bit word length.

This example shows how to create a signed numerictype object with binary-point scaling, a 32-bit word length, and 30-bit fraction length.

T = numerictype(1,32,30)
T =


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 30

This example shows how to create a numerictype object with slope and bias scaling. The real-world value of a slope and bias scaled number is represented by:

realworldvalue=(slope×integer)+bias

Create a numerictype object that describes a signed, fixed-point data type with a word length of 16 bits, a slope of 2^-2, and a bias of 4.

T = numerictype(1,16,2^-2,4)
T =


          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 0.25
                  Bias: 4

Alternatively, the slope can be represented by:

slope=slopeadjustmentfactor×2fixedexponent

Create a numerictype object that describes a signed, fixed-point data type with a word length of 16 bits, a slope adjustment factor of 1, a fixed exponent of -2, and a bias of 4.

T = numerictype(1,16,1,-2,4)
T =


          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 16
                 Slope: 0.25
                  Bias: 4

This example shows how to use name-value pairs to set numerictype properties at object creation.

T = numerictype('Signed',true,'DataTypeMode','Fixed-point: slope and bias scaling', ...
    'WordLength',32,'Slope',2^-2,'Bias',4)
T =


          DataTypeMode: Fixed-point: slope and bias scaling
            Signedness: Signed
            WordLength: 32
                 Slope: 0.25
                  Bias: 4

This example shows how to create a numerictype object with an unspecified sign by using name-value pairs to set the Signedness property to Auto.

T = numerictype('Signedness','Auto')
T =


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Auto
            WordLength: 16
        FractionLength: 15

This example shows how to create a numerictype object with a specific data type by using arguments and name-value pairs.

T = numerictype(0,24,12,'DataType','ScaledDouble')
T =


          DataTypeMode: Scaled double: binary point scaling
            Signedness: Unsigned
            WordLength: 24
        FractionLength: 12

The returned numerictype object, T, is unsigned, and has a word length of 24 bits, a fraction length of 12 bits, and a data type set to scaled double.

This example shows how to create a numerictype object with data type set to single, double, or Boolean at object creation.

Create a numerictype object with the data type mode set to single.

T = numerictype('Single')
T =


          DataTypeMode: Single

Create a numerictype object with the data type mode set to double.

T = numerictype('Double')
T =


          DataTypeMode: Double

Create a numerictype object with the data type mode set to Boolean.

T = numerictype('Boolean')
T =


          DataTypeMode: Boolean

Input Arguments

collapse all

Whether the object is signed, specified as a numeric or logical 1 (true) or 0 (false).

Example: T = numerictype(true)

Data Types: logical

Word length, in bits, of the stored integer value, specified as a positive integer.

Example: T = numerictype(true,16)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fraction length, in bits, of the stored integer value, specified as an integer.

Fraction length can be greater than word length. For more information, see Binary Point Interpretation (Fixed-Point Designer).

Example: T = numerictype(true,16,15)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Slope, specified as a finite floating-point number greater than zero.

The slope and the bias determine the scaling of a fixed-point number.

Note

slope=slope adjustment factor×2fixed exponent

Changing one of these properties affects the others.

Example: T = numerictype(true,16,2^-2,4)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Bias associated with the object, specified as a floating-point number.

The slope and the bias determine the scaling of a fixed-point number.

Example: T = numerictype(true,16,2^-2,4)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Slope adjustment factor, specified as a positive scalar.

The slope adjustment factor must be greater than or equal to 1 and less than 2. If you input a slopeadjustmentfactor outside this range, the numerictype object automatically applies a scaling normalization to the values of slopeadjustmentfactor and fixedexponent so that the revised slope adjustment factor is greater than or equal to 1 and less than 2, and maintains the value of the slope.

The slope adjustment is equivalent to the fractional slope of a fixed-point number.

Note

slope=slope adjustment factor×2fixed exponent

Changing one of these properties affects the others.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point exponent associated with the object, specified as an integer.

Note

The FixedExponent property is the negative of the FractionLength. Changing one property changes the other.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: F = numerictype('DataTypeMode','Fixed-point: binary point scaling','DataTypeOverride','Inherit')

Note

When you create a numerictype object by using name-value pairs, Fixed-Point Designer™ creates a default numerictype object, and then, for each property name you specify in the constructor, assigns the corresponding value. This behavior differs from the behavior that occurs when you use a syntax such as T = numerictype(s,w). See Example: Construct a numerictype Object with Property Name and Property Value Pairs.

Bias, specified as a floating-point number.

The slope and bias determine the scaling of a fixed-point number.

Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','Bias',4)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Data type category, specified as one of these values:

  • 'Fixed' – Fixed-point or integer data type

  • 'Boolean' – Built-in MATLAB® Boolean data type

  • 'Double' – Built-in MATLAB double data type

  • 'ScaledDouble' – Scaled double data type

  • 'Single' – Built-in MATLAB single data type

Example: T = numerictype('Double')

Data Types: char

Data type and scaling mode associated with the object, specified as one of these values:

  • 'Fixed-point: binary point scaling' – Fixed-point data type and scaling defined by the word length and fraction length

  • 'Fixed-point: slope and bias scaling' – Fixed-point data type and scaling defined by the slope and bias

  • 'Fixed-point: unspecified scaling' – Fixed-point data type with unspecified scaling

  • 'Scaled double: binary point scaling' – Double data type with fixed-point word length and fraction length information retained

  • 'Scaled double: slope and bias scaling' – Double data type with fixed-point slope and bias information retained

  • 'Scaled double: unspecified scaling' – Double data type with unspecified fixed-point scaling

  • 'Double' – Built-in double

  • 'Single' – Built-in single

  • 'Boolean' – Built-in boolean

Example: T = numerictype('DataTypeMode','Fixed-point: binary point scaling')

Data Types: char

Data type override settings, specified as one of these values:

  • 'Inherit' – Turn on DataTypeOverride

  • 'Off' – Turn off DataTypeOverride

Note

The DataTypeOverride property is not visible when its value is set to the default, 'Inherit'.

Example: T = numerictype('DataTypeOverride','Off')

Data Types: char

Fixed-point exponent associated with the object, specified as an integer.

Note

The FixedExponent property is the negative of the FractionLength. Changing one property changes the other.

Example: T = numerictype('FixedExponent',-12)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fraction length, in bits, of the stored integer value, specified as an integer.

The default value is the best precision fraction length based on the value of the object and the word length.

Example: T = numerictype('FractionLength',12)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-point scaling mode of the object, specified as one of these values:

  • 'BinaryPoint' – Scaling for the numerictype object is defined by the fraction length.

  • 'SlopeBias' – Scaling for the numerictype object is defined by the slope and bias.

  • 'Unspecified' – Temporary setting that is only allowed at numerictype object creation, and allows for the automatic assignment of a best-precision binary point scaling.

Example: T = numerictype('Scaling','BinaryPoint')

Data Types: char

Whether the object is signed, specified as a numeric or logical 1 (true) or 0 (false).

Note

Although the Signed property is still supported, the Signedness property always appears in the numerictype object display. If you choose to change or set the signedness of your numerictype object using the Signed property, MATLAB updates the corresponding value of the Signedness property.

Example: T = numerictype('Signed',true)

Data Types: logical

Whether the object is signed, specified as one of these values:

  • 'Signed' – Signed

  • 'Unsigned' – Unsigned

  • 'Auto' – Unspecified sign

Note

Although you can create numerictype objects with an unspecified sign (Signedness: Auto), all fixed-point numerictype objects must have a Signedness of Signed or Unsigned. If you use a numerictype object with Signedness: Auto to construct a numerictype object, the Signedness property of the numerictype object automatically defaults to Signed.

Example: T = numerictype('Signedness','Signed')

Data Types: char

Slope, specified as a finite, positive floating-point number.

The slope and bias determine the scaling of a fixed-point number.

Note

slope=slope adjustment factor×2fixed exponent

Changing one of these properties affects the others.

Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','Slope',2^-2)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Slope adjustment factor, specified as a positive scalar.

The slope adjustment factor must be greater than or equal to 1 and less than 2. If you input a slopeadjustmentfactor outside this range, the numerictype object automatically applies a scaling normalization to the values of slopeadjustmentfactor and fixedexponent so that the revised slope adjustment factor is greater than or equal to 1 and less than 2, and maintains the value of the slope.

The slope adjustment is equivalent to the fractional slope of a fixed-point number.

Note

slope=slope adjustment factor×2fixed exponent

Changing one of these properties affects the others.

Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias scaling','SlopeAdjustmentFactor',1.5)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Word length, in bits, of the stored integer value, specified as a positive integer.

Example: T = numerictype('WordLength',16)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Extended Capabilities

HDL Code Generation
Generate Verilog and VHDL code for FPGA and ASIC designs using HDL Coder™.

Introduced before R2006a