This class defines the precision of a signed or unsigned fixed point value. The precision of a fixed point value is represented as internally as three fields: the number of bits (
n), the binary exponent (
e), and a sign bit (
s). The number of bits (
n) defines the dynamic range of the format (2
n). The exponent (
e) determines the placement of the binary point for all values of this format. This binary point placement is "fixed" and is specified within the precision format rather than within individual Fixed point values. The mantissa bits of all fixed point values using this this precision format are multiplied by 2
m. Note that
m can take on a positive, negative, or zero value. This allows the binary point to be placed anywhere necessary and even beyond the bounds of the mantissa (i.e. to the right of the lsb or to the left of the msb). The sign value
s is used to indicate whether the fixed point precision value is treated as signed (s = 1) or unsigned (s = 0).
Signed fixed point formats are represented in a 2's complement format. As a consequence, a single bit is used to represent the sign of the number. The value of a multi-bit signed number is:
Signed(B) = 2^m x (- b_{n-1} x 2^{n-1} + \sum_{i=0}^{n-2} b_i x 2^i), where b_i is the value of bit i of the bit vector.
Unsigned fixed formats are represented as unsigned binary values. No bits are used to represent the sign and all values are positive. The actual value of a multi-bit unsigned fixed point number is:
Unsigned(B) = 2^m x (\sum_{i=0}^{n-1} b_i x 2^i)
This class supports several different String formats for specifying and displaying the Precision. These String formats are supported by several classes that extend the {@link PrecisionFormat} class. Several such classeshave been created. Any given precision string format can be represented in any of the valid precision string formats. The four supported Precision String formats are shown in the table below. A static singleton object of each of these formats is provided in this class. Each String Representation column of the table represent equivalent Precision formats:
Format Name | Format Spec | String Representation |
{@link IntegerFractionPrecisionFormat} | [integer bits].[fraction bits] | 3.2 | 0.7 | -2.12 | 12.-4 | 32.0 | U1.7 |
{@link LengthIntegerPrecisionFormat} | [total bits]/[integer bits] | 5/3 | 7/0 | 10/-2 | 8/12 | 32/32 | U8/1 |
{@link VHDLPrecisionFormat} | [MSb position]:[LSb position] | 2:-2 | -1:-7 | -3:-12 | 11:4 | 31:0 | U0:-7 |
{@link LengthExponentPrecisionFormat} | \ [total bits]e[binary point position] | 5e-2 | 7e-7 | 10e-12 | 8e4 | 32e0 | U8e-7 |
An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified.
@author Bart Kienhuis, Contributor: Mike Wirthlin
@version $Id: Precision.java,v 1.73 2007/12/06 21:57:08 cxh Exp $
@since Ptolemy II 0.4
@Pt.ProposedRating Yellow (kienhuis)
@Pt.AcceptedRating Red (kienhuis)
@see FixPoint