The FixPoint class provides a fixed point data type and a set of functions that operate on and return fixed point data. An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified. This is similar to the Java built-in classes like Double, Integer, etc.
The FixPoint class represents signed numbers in a two's-complement format or unsigned numbers in a binary format with unlimited dynamic range and a resolution defined by a finite number of fractional bits. The precision is defined by the {@link ptolemy.math.Precision Precision} class.
Because a fixed point data type uses a finite number of bits to represent a value, a real value is converted to a number that can be expressed with a given precision of the fixed point, thereby introducing a quantization error. The overflow and rounding strategies used for this quantization are defined by an instance of the {@link ptolemy.math.Quantization Quantization} class.
The design of the FixPoint class complies with a philosophy that all operators work losslessly, i.e. the fractional precision of the result is determined such there is no loss of precision. To insure lossless operations, the resulting Precision of these operators will expand as necessary. Subsequent results can be quantized as necessary.
Violations of the loss-less philosophy occur during construction, division and conversion to floating point. During construction from floating point values, the nearest fixed point representation is created. The preferred divide operator provides for explicit specification of the quantization. A deprecated divide operator guesses at the result precision. Conversion to floating point is limited by the available floating point accuracy.
The FixPoint implementation uses the Java class BigInteger to represent the finite value and so this implementation is truly platform independent. Note that the FixPoint does not put any restrictions on the maximum number of bits in the representation of a value.
@author Bart Kienhuis, Ed Willink, Contributor: Edward A. Lee, Mike Wirthlin
@version $Id: FixPoint.java,v 1.84 2007/12/07 06:30:32 cxh Exp $
@since Ptolemy II 0.4, rewritten for Ptolemy II 2.2
@Pt.ProposedRating Red (Ed.Willink)
@Pt.AcceptedRating Red
@see ptolemy.math.Precision
@see ptolemy.math.Quantization