|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectptolemy.math.Precision
This class describes the precision of an instance of FixPoint. An instance of FixPoint represents a fixed point number as two finite bit sequences: an integer part and a fractional part. The total length of a fixed point value is the combined length of the integer part and the fractional part.
There are two string formats for precision, either of which is understood by the constructor that takes a string argument:
The FixPoint class represents signed numbers in a 2's complement format. As a consequence, a single bit is used to represent the sign of the number. Therefore, when a precision is given of, for example, (6, 3), then 6 bits are used for the integer part and 3 are used for the fractional part. Of the 6 integer bits, 5 are used to represent a number and 1 is used for the sign.
In giving a precision, at least a single bit is required to describe the sign and thus the minimum precision that can be given to a FixPoint is equal to (1.0). Since a single bit is used, the FixPoint represents the numbers 0 and -1. Note that a precision of (2.0) represents the numbers 1, 0, -1, and -2. The representation is two's complement.
An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified.
FixPoint,
Serialized Form
| Red (kienhuis) |
| Yellow (kienhuis) |
| Constructor Summary | |
Precision(int length,
int integerBits)
Construct a Precision object based on the provided numbers. |
|
Precision(java.lang.String precision)
Construct a Precision object based on the provided string. |
|
| Method Summary | |
java.lang.Object |
clone()
Return this, that is, return the reference to this object. |
boolean |
equals(java.lang.Object object)
Return true if the indicated object is an instance of Precision and the number of integer and fractional bits both match. |
java.math.BigDecimal |
findMaximum()
Return the maximum obtainable value in this precision. |
java.math.BigDecimal |
findMinimum()
Return the minimum obtainable value for this precision. |
int |
getFractionBitLength()
Return the number of bits representing the fractional part. |
int |
getIntegerBitLength()
Return the number of bits representing the integer part. |
int |
getNumberOfBits()
Return the total number of bits. |
static Precision |
matchThePoint(Precision precisionA,
Precision precisionB)
Return the precision that is the maximum of the two supplied precisions in both the integer and fractional part. |
java.lang.String |
toString()
Return a string representing this precision. |
| Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Precision(java.lang.String precision)
throws java.lang.IllegalArgumentException
precision - The string representing the precision.
java.lang.IllegalArgumentException - If the precision string
supplied does not match one of the known formats.
public Precision(int length,
int integerBits)
throws java.lang.IllegalArgumentException
length - The total number of bits.integerBits - The number of integer bits.
java.lang.IllegalArgumentException - If the given values are
negative or when the integer number of bits is larger than the
total number of bits.| Method Detail |
public java.lang.Object clone()
public boolean equals(java.lang.Object object)
public java.math.BigDecimal findMaximum()
public java.math.BigDecimal findMinimum()
public int getFractionBitLength()
public int getIntegerBitLength()
public int getNumberOfBits()
public static Precision matchThePoint(Precision precisionA,
Precision precisionB)
precisionA - A precisionprecisionB - Another precision
public java.lang.String toString()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||