This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Determine maximum precision available for fixed-point representation of value


out = fixptbestprec(RealWorldValue,TotalBits,IsSigned)
out = fixptbestprec(RealWorldValue,FixPtDataType)


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:

out = fixptbestprec(4/3,8,1)
out =

Alternatively, you can specify the fixed-point data type:

out = fixptbestprec(4/3,sfix(8))
out =

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 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 expression that you specify for the Output data type parameter in a block mask. Be sure to select the Lock output data type setting against changes by the fixed-point tools check box in the same block to prevent the Fixed-Point Tool from overriding the scaling. 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 autofixexp in the Fixed-Point Designer™ documentation.

See Also

Introduced before R2006a

Was this topic helpful?