| Simulink Reference | ![]() |
Determine the maximum precision available for the fixed-point representation of a value
Syntax
out = fixptbestprec(RealWorldValue,TotalBits,IsSigned) out = fixptbestprec(RealWorldValue,FixPtDataType)
Description
out = fixptbestprec(RealWorldValue,TotalBits,IsSigned)
determines the maximum precision for the fixed-point representation of the real-world value specified by RealWorldValue. You specify the number of bits for the fixed- point number with TotalBits, and you specify whether the fixed-point number is signed with IsSigned. If IsSigned is 1, the number is signed. If IsSigned is 0, the number is not signed. The maximum precision is returned to out.
out = fixptbestprec(RealWorldValue,FixPtDataType)
determines the maximum precision based on the data type specified by FixPtDataType.
Example 1.
The following command returns the maximum precision available for the real-world value 4/3 using a signed, 8-bit number:
Alternatively, you can specify the fixed-point data type:
This value means that the maximum precision available for 4/3 is obtained by placing six bits to the right of the binary point since 2-6 equals 0.015625:
Example 2.
You can use the maximum precision as the scaling parameter in fixed-point blocks. This enables you to use fixptbestprec to perform a type of autoscaling if you would like to designate a known range of your simulation. For example, if your known range is -13 to 22, and you are using a safety margin of 30%:
knownMax = 22; knownMin = -13; localSafetyMargin = 30; slope = max( fixptbestprec( (1+localSafetyMargin/100)*[knownMax, knownMin], sfix(16) ) );
The variable slope can then be used in the Output scaling value parameter in a block mask in your model. Be sure to select the Lock output scaling against changes by the autoscaling tool parameter in the same block to prevent the scaling from being overridden by the Fixed-Point Settings interface. If you know the range, you can use this technique in place of relying on a model simulation to provide the range to the autoscaling tool, as described in the autofixexp reference page.
See Also
| fixptbestexp | fixpt_evenspace_cleanup | ![]() |
© 1994-2005 The MathWorks, Inc.