numerictype
Create an embedded.numerictype object describing fixed-point or
floating-point data type
Description
The numerictype object allows you to set properties that
determine how a fi object interprets stored data as a real-world
value.
Creation
Use the numerictype function described here to create a
numerictype object.
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
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 s, word length w,
slopeadjustmentfactor, fixedexponent, and
bias.
T = numerictype(___,
allows you to set properties using name-value arguments. All properties that you do not
specify a value for are assigned their default values.PropertyName=Value)
T = numerictype(T1,
allows you to make a copy, PropertyName=Value)T, of an existing
numerictype object, T1, while modifying any or all
of the property values.
T = numerictype(' creates a
typename')numerictype object with the same numeric attributes as the
MATLAB® or Simulink® built-in data type typename.
T = numerictype( creates a
a)numerictype object with the numeric type attributes of the
fi object, a.
Input Arguments
Signedness of the numerictype object, specified as a numeric or
logical 1 (true) or 0
(false).
Specify an empty array [] to automate signedness.
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 of the fi
object, specified as a scalar integer. The fraction length must be an integer in the
range -65535 ≤ f ≤ 65535.
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
Data type name of a built-in data type, specified as a character vector or string.
Use this input argument to create a numerictype object with the same
data type and scaling attributes as the type specified.
The following input types are supported:
MATLAB data type name strings —
'half','single','double','int8','int16','int32','int64','uint8','uint16','uint32','uint64','logical'Simulink data type name strings (not aliases) —
'bool','sfix16_En3', etc.
Example: T = numerictype('single')
Data Types: char | string
Properties
numerictype object properties define the data type and scaling attributes
of a fixed-point object. All properties of a numerictype object are writable.
The properties of the numerictype object can also be specified as
name-value arguments when constructing a fi object. However, the
numerictype properties of a fi object become read-only
after the fi object has been created. Any numerictype
properties of a fi object that are unspecified at the time of
fi object creation are automatically set to their default values.
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
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 signed or unsigned numerictype object with the default word length and scaling.
Set the signedness argument, s, to 1 to create a signed numerictype object. Omit 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.
Create an unsigned numerictype object by setting the signedness argument to 0.
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 arguments 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 arguments 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 arguments.
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 using the name of a built-in MATLAB® or Simulink® data type.
Create a numerictype object with the same data type and scaling attributes as the MATLAB data type int8.
T = numerictype('int8')T =
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 8
FractionLength: 0
Create a numerictype object with the same data type and scaling attributes as the Simulink data type sfix16_En3.
S = numerictype('sfix16_En3')S =
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 3
This example shows you how to create a numerictype object from an existing fi object.
Create a fi object with default properties and no value specified.
a = fi
a =
[]
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 15
Create a numerictype object using a as the input.
T = numerictype(a)
T =
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 15
T has the same numeric type attributes as a.
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.If the input signal to the
numerictypefunction is not fixed-point, the function will return information about the data type of that signal.The
numerictypefunction can be used to createnumerictypeobjects 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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- 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)