numerictype オブジェクトを使用した fi オブジェクトのデータ型とスケーリング設定の共有
numerictype
オブジェクトを使用して、多くの fi
オブジェクトで使用する共通のデータ型とスケーリングのルールを定義することができます。その後で、それぞれに対して同じ numerictype
オブジェクトを使用し、複数の fi
オブジェクトを作成できます。
例 1
以下の例では、語長 32
ビット、小数部の長さ 28
ビットの numerictype
オブジェクト T
を作成します。次に fi
オブジェクトが同じ numerictype
属性をもつことを確認するために、numerictype
オブジェクト T
を使用し、fi
オブジェクト a
と b
を作成します。
format long g T = numerictype('WordLength',32,'FractionLength',28)
T = DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 28
a = fi(pi,T)
a = 3.1415926553309 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 28
b = fi(pi/2,T)
b = 1.5707963258028 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 28
例 2
以下の例ではまず [勾配 バイアス] スケーリングをもつ numerictype
オブジェクト T
を作成します。次にこのオブジェクトを使用し、同じ numerictype
属性をもつ 2 つの fi
オブジェクト c
と d
を作成します。
T = numerictype('Scaling','slopebias','Slope',2^2,'Bias',0)
T = DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 2^2 Bias: 0
c = fi(pi,T)
c = 4 DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 2^2 Bias: 0
d = fi(pi/2,T)
d = 0 DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 2^2 Bias: 0
numerictype
オブジェクトのプロパティについての詳細は、numerictype オブジェクト プロパティを参照してください。