主要内容

numerictype

构造描述定点或浮点数据类型的 embedded.numerictype 对象

说明

T = numerictype 创建一个默认的 numerictype 对象。

示例

T = numerictype(s) 创建一个定点 numerictype 对象,该对象未指定定标类型,具有有符号属性值 s 和 16 位字长。

示例

T = numerictype(s,w) 创建一个定点 numerictype 对象,该对象未指定定标类型,具有有符号属性值 s 和字长 w

示例

T = numerictype(s,w,f) 创建一个定点 numerictype 对象,该对象具有二进制小数点定标、有符号属性值 s、字长 w 和小数长度 f

示例

T = numerictype(s,w,slope,bias) 创建一个定点 numerictype 对象,该对象具有斜率和偏置定标、有符号属性值 s、字长 w、斜率 slope 和偏置 bias

示例

T = numerictype(s,w,slopeadjustmentfactor,fixedexponent,bias) 创建一个定点 numerictype 对象,该对象具有斜率和偏置定标、有符号属性值 s、字长 w、斜率 slopeadjustmentfactorfixedexponent 和偏置 bias

示例

T = numerictype(___,Name,Value) 允许您使用名称-值对组设置属性。所有未指定值的属性都被赋予其默认值。

示例

T = numerictype(T1,Name,Value) 允许您在修改任一或所有属性值时创建现有 numerictype 对象 T 的副本 T1

示例

T = numerictype('Double') 创建一个双精度数据类型的 numerictype 对象。

示例

T = numerictype('Single') 创建一个单精度数据类型的 numerictype 对象。

示例

T = numerictype('Half') 创建一个半精度数据类型的 numerictype 对象。

示例

T = numerictype('Boolean') 创建一个布尔数据类型的 numerictype 对象。

示例

示例

全部折叠

此示例说明如何使用默认属性设置创建 numerictype 对象。

T = numerictype
T =


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

此示例说明如何通过省略字长 w 和小数长度 f 参量,创建一个具有默认字长和定标的 numerictype 对象。

T = numerictype(1)
T =


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

对象为有符号对象,字长为 16 位,未指定定标。

您可以使用符号性参量 s 创建一个无符号 numerictype 对象。

T = numerictype(0)
T =


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

对象的默认字长为 16 位,未指定定标。

此示例说明如何通过省略小数长度参量 f 创建一个具有 32 位字长且未指定定标的 numerictype 对象。

T = numerictype(1,32)
T =


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

对象为有符号对象。

此示例说明如何创建一个有符号 numerictype 对象,该对象具有二进制小数点定标、32 位字长和 30 位小数长度。

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


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

此示例说明如何创建一个具有斜率和偏置定标的 numerictype 对象。斜率和偏置定标数的真实值由下式表示:

realworldvalue=(slope×storedinteger)+bias

创建一个 numerictype 对象,该对象描述一种字长为 16 位、斜率为 2^-2、偏置为 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

或者,斜率可以表示为:

slope=slopeadjustmentfactor×2fixedexponent

创建一个 numerictype 对象,该对象描述一个有符号定点数据类型,其字长为 16 位、斜率调整因子为 1、固定指数为 -2、偏置为 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

此示例说明如何在创建对象时使用名称-值对组来设置 numerictype 属性。

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

此示例说明如何通过使用名称-值对组将 Signedness 属性设置为 Auto,创建一个具有未指定 Signednessnumerictype 对象。

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


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

此示例说明如何使用参量和名称-值对组创建一个具有特定数据类型的 numerictype 对象。

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


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

返回的 numerictype 对象 T 是无符号对象,其字长为 24 位、小数长度为 12 位、数据类型设置为定标双精度。

此示例说明如何创建一个数据类型设置为 DoubleSingle HalfBooleannumerictype 对象。

创建一个 numerictype 对象,其数据类型模式设置为 Double

T = numerictype('Double')
T =


          DataTypeMode: Double

创建一个 numerictype 对象,其数据类型模式设置为 Single

T = numerictype('Single')
T =


          DataTypeMode: Single

创建一个 numerictype 对象,其数据类型模式设置为 Half

T = numerictype('Half')
T =


          DataTypeMode: Half

创建一个 numerictype 对象,其数据类型模式设置为 Boolean

T = numerictype('Boolean')
T =


          DataTypeMode: Boolean

输入参数

全部折叠

对象是否为有符号对象,指定为数值或逻辑值 1 (true) 或 0 (false)。

示例: T = numerictype(true)

数据类型: logical

存储的整数值的字长(以位为单位),指定为正整数。

示例: T = numerictype(true,16)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

存储的整数值的小数长度(以位为单位),指定为整数。

小数长度可以大于字长。有关详细信息,请参阅二进制小数点的解释 (Fixed-Point Designer)。

示例: T = numerictype(true,16,15)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率,指定为大于零的有限浮点数。

斜率和偏置确定定点数的定标。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

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

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

与对象相关联的偏置,指定为浮点数。

斜率和偏置确定定点数的定标。

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

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率调整因子,指定为正标量。

斜率调整因子必须大于或等于 1 且小于 2。如果您输入的 slopeadjustmentfactor 超出此范围,numerictype 对象会自动对 slopeadjustmentfactorfixedexponent 的值应用定标归一化,以便修正后的斜率调整因子大于或等于 1 且小于 2 并保持斜率值。

斜率调整等效于定点数的小数斜率。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

与对象相关联的定点指数,指定为整数。

注意

FixedExponent 属性是 FractionLength 的负数。更改一个属性会更改另一个属性。

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

名称-值参数

全部折叠

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

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

注意

当您使用名称-值对组创建 numerictype 对象时,Fixed-Point Designer™ 会创建一个默认 numerictype 对象,然后为您在构造函数中指定的每个属性名称分配对应的值。此行为不同于在使用 T = numerictype(s,w) 等语法时发生的行为。请参阅Example: Construct a numerictype Object with Property Name and Property Value Pairs

偏置,指定为浮点数。

斜率和偏置确定定点数的定标。

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

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

数据类型类别,指定为以下值之一:

  • 'Fixed' - 定点或整数数据类型

  • 'Boolean' - 内置 MATLAB® 布尔数据类型

  • 'Double' - 内置 MATLAB 双精度数据类型

  • 'ScaledDouble' - 定标双精度数据类型

  • 'Single' - 内置 MATLAB 单精度数据类型

  • 'Half' - MATLAB 半精度数据类型

示例: T = numerictype('Double')

数据类型: char

与对象关联的数据类型和定标模式,指定为以下值之一:

  • 'Fixed-point: binary point scaling' - 由字长和小数长度定义的定点数据类型和定标

  • 'Fixed-point: slope and bias scaling' - 由斜率和偏置定义的定点数据类型和定标

  • 'Fixed-point: unspecified scaling' - 具有未指定的定标的定点数据类型

  • 'Scaled double: binary point scaling' - 保留定点字长和小数长度信息的双精度数据类型

  • 'Scaled double: slope and bias scaling' - 保留定点斜率和偏置信息的双精度数据类型

  • 'Scaled double: unspecified scaling' - 未指定定点定标的双精度数据类型

  • 'Double' - 内置 double

  • 'Single' - 内置 single

  • 'Half' - MATLAB 半精度数据类型

  • 'Boolean' - 内置 boolean

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

数据类型: char

数据类型覆盖设置,指定为以下值之一:

  • 'Inherit' - 打开 DataTypeOverride

  • 'Off' - 关闭 DataTypeOverride

注意

DataTypeOverride 属性的值设置为默认值 'Inherit' 时,该属性不可见。

示例: T = numerictype('DataTypeOverride','Off')

数据类型: char

与对象相关联的定点指数,指定为整数。

注意

FixedExponent 属性是 FractionLength 的负数。更改一个属性会更改另一个属性。

示例: T = numerictype('FixedExponent',-12)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

存储的整数值的小数长度(以位为单位),指定为整数。

默认值为基于对象值和字长的最佳精度小数长度。

注意

FractionLength 属性是 FixedExponent 的负数。更改一个属性会更改另一个属性。

示例: T = numerictype('FractionLength',12)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

对象的定点定标模式,指定为以下值之一:

  • 'BinaryPoint' - numerictype 对象的定标由小数长度定义。

  • 'SlopeBias' - numerictype 对象的定标由斜率和偏置定义。

  • 'Unspecified' - 仅在 numerictype 对象创建时允许的临时设置,它允许自动赋予最佳精度二进制小数点定标。

示例: T = numerictype('Scaling','BinaryPoint')

数据类型: char

对象是否为有符号对象,指定为数值或逻辑值 1 (true) 或 0 (false)。

注意

尽管仍支持 Signed 属性,但 Signedness 属性会始终出现在 numerictype 对象显示中。如果您选择使用 Signed 属性更改或设置 numerictype 对象的符号性,MATLAB 会更新 Signedness 属性的对应值。

示例: T = numerictype('Signed',true)

数据类型: logical

对象是否为有符号对象,指定为以下值之一:

  • 'Signed' - 有符号

  • 'Unsigned' - 无符号

  • 'Auto' - 未指定符号

注意

尽管您可以创建具有未指定符号 (Signedness: Auto) 的 numerictype 对象,但所有定点 numerictype 对象的 Signedness 值都必须为 SignedUnsigned。如果使用 numerictype 对象和 Signedness: Auto 来构造 numerictype 对象,则 numerictype 对象的 Signedness 属性自动默认为 Signed

示例: T = numerictype('Signedness','Signed')

数据类型: char

斜率,指定为有限正浮点数。

斜率和偏置确定定点数的定标。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

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

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

斜率调整因子,指定为正标量。

斜率调整因子必须大于或等于 1 且小于 2。如果您输入的 slopeadjustmentfactor 超出此范围,numerictype 对象会自动对 slopeadjustmentfactorfixedexponent 的值应用定标归一化,以便修正后的斜率调整因子大于或等于 1 且小于 2 并保持斜率值。

斜率调整等效于定点数的小数斜率。

注意

slope=slope adjustment factor×2fixed exponent

更改其中一个属性会影响其他属性。

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

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

存储的整数值的字长(以位为单位),指定为正整数。

示例: T = numerictype('WordLength',16)

数据类型: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

扩展功能

全部展开

HDL 代码生成
使用 HDL Coder™ 为 FPGA 和 ASIC 设计生成 VHDL、Verilog 和 SystemVerilog 代码。

版本历史记录

在 R2006a 之前推出

全部展开