Numerictype for fimath output
2 次查看(过去 30 天)
显示 更早的评论
When adding two fixed point numbers, I am not understanding the output I am getting. I think it may have to do with a subtlety I am missing with fimath properties. Here is an example:
FMval = fimath;
FMval.SumMode = 'KeepMSB';
FMval.SumWordLength = bitDepthd;
FMval.ProductMode = 'KeepMSB';
FMval.ProductWordLength = bitDepthd;
FMval.OverflowAction = 'Saturate';
FMval.RoundingMethod = 'Nearest';
A = fi(3, 0, 4, 0, FMval);
B = fi(5, 0, 4, 0, FMval);
I would think that A+B = 8, but when I add them together:
>> C = A+B
C =
10
DataTypeMode: Fixed-point: binary point scaling
Signedness: Unsigned
WordLength: 4
FractionLength: -1
Why is the answer not 8? Why did the FractionLength go to -1? There is no overflow in this addition, and both variables have a fractionlength of 0.
I understand that adding two four bit numbers requires 5 bits, and then I could maybe understand an answer of, say, sixteen (moving the fractionlength to -1), but 5(0011 bin) + 3(0011 bin) should not equal 10 any way I can figure.
Another example, this time with a 4-bit overflow:
D = fi(12, 0, 4, 0, FMval); E = fi(7, 0, 4, 0, FMval);
>> F = E+D
F =
20
DataTypeMode: Fixed-point: binary point scaling
Signedness: Unsigned
WordLength: 4
FractionLength: -1
What am I missing here? Is there a way to set the fimath properties to get the answers I'm expecting?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Create Fixed-Point Objects in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!