Local solution:
You can use an fimath
object to specify the precision of the result of a product:
F = fimath('OverflowMode','Wrap', 'RoundMode', 'Floor', ...
'ProductMode', 'SpecifyPrecision', ...
'ProductWordLength', 16, 'ProductFractionLength', 2);
dis.fimath = F;
Then the result will be:
>> dis*dis
ans =
2.25
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 2
RoundMode: floor
OverflowMode: wrap
ProductMode: SpecifyPrecision
ProductWordLength: 16
ProductFractionLength: 2
SumMode: FullPrecision
MaxSumWordLength: 128
Global solution: Alternatively, if you want this to apply to all your fixedpoint variables you can use
globalfimath('OverflowMode','Wrap', 'RoundMode', 'Floor', ...
'ProductMode', 'SpecifyPrecision', ...
'ProductWordLength', 16, 'ProductFractionLength', 2);
Note that to limit to 16 bit you need to specify the precision for sum as well (using SumMode
and SumWordLength
properties of fimath
) otherwise the sum will have a word length of 17:
>> dis+dis
ans =
3
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 17
FractionLength: 2