numerictype
Construct an embedded.numerictype object describing fixed-point
or floating-point data type
Syntax
Description
T = numerictype creates a default numerictype
object.
T = numerictype( creates a fixed-point
s)numerictype object with unspecified scaling, a signed property value of
s, and a 16-bit word length.
T = numerictype(
creates a fixed-point s,w,slopeadjustmentfactor,fixedexponent,bias)numerictype object with slope and bias scaling, a
signed property value of s, word length of w,
slopeadjustmentfactor, fixedexponent, and
bias.
T = numerictype(___,
allows you to set properties using name-value pairs. All properties that you do not specify
a value for are assigned their default values.Name,Value)
T = numerictype(T1, allows you to
make a copy, Name,Value)T1, of an existing numerictype object,
T, while modifying any or all of the property values.
T = numerictype('Double') creates a numerictype
object of data type double.
T = numerictype('Single') creates a numerictype
object of data type single.
T = numerictype('Half') creates a numerictype
object of data type half.
T = numerictype('Boolean') creates a numerictype
object of data type Boolean.
Examples
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 has the default word length of 16 bits and unspecified scaling.
This example shows how to create a numerictype object with a 32-bit word length and 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.
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:
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:
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 Signedness 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 Double, Single, Half, or Boolean at object creation.
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 Single.
T = numerictype('Single')T =
DataTypeMode: Single
Create a numerictype object with the data type mode set to Half.
T = numerictype('Half')T =
DataTypeMode: Half
Create a numerictype object with the data type mode set to Boolean.
T = numerictype('Boolean')T =
DataTypeMode: Boolean
Input Arguments
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: half | 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: half | 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
Changing one of these properties affects the others.
Example: T = numerictype(true,16,2^-2,4)
Data Types: half | 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: half | 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
Changing one of these properties affects the others.
Data Types: half | 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: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
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: half | 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'Half'– MATLAB half-precision 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-indouble'Single'– Built-insingle'Half'– MATLAB half-precision data type'Boolean'– Built-inboolean
Example: T = numerictype('DataTypeMode','Fixed-point: binary point
scaling')
Data Types: char
Data type override settings, specified as one of these values:
'Inherit'– Turn onDataTypeOverride'Off'– Turn offDataTypeOverride
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: half | 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.
Note
The FractionLength property is the negative of the
FixedExponent. Changing one property changes the other.
Example: T = numerictype('FractionLength',12)
Data Types: half | 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 thenumerictypeobject is defined by the fraction length.'SlopeBias'– Scaling for thenumerictypeobject is defined by the slope and bias.'Unspecified'– Temporary setting that is only allowed atnumerictypeobject 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
Changing one of these properties affects the others.
Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias
scaling','Slope',2^-2)
Data Types: half | 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
Changing one of these properties affects the others.
Example: T = numerictype('DataTypeMode','Fixed-point: slope and bias
scaling','SlopeAdjustmentFactor',1.5)
Data Types: half | 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: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Extended Capabilities
Usage notes and limitations:
Fixed-point signals coming in to a MATLAB Function block from Simulink® are assigned a
numerictypeobject that is populated with the signal's data type and scaling information.Returns the data type when the input is a non fixed-point signal.
Use to create
numerictypeobjects in generated code.All
numerictypeobject properties related to the data type must be constant.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
Version History
Introduced before R2006aIn previous releases, inexact property names for fi,
fimath, and numerictype objects would result in a
warning. In R2021a, support for inexact property names was removed. Use exact property names
instead.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)