ptolemy.data
Class FixToken

java.lang.Object
  |
  +--ptolemy.data.Token
        |
        +--ptolemy.data.ScalarToken
              |
              +--ptolemy.data.FixToken
All Implemented Interfaces:
java.io.Serializable

public class FixToken
extends ScalarToken

A token that contains an instance of FixPoint.

Since:
Ptolemy II 0.4
Version:
$Id: FixToken.java,v 1.46.2.1 2002/04/11 15:20:23 cxh Exp $
Author:
Bart Kienhuis, Contributor: Edward A. Lee
See Also:
Token, FixPoint, Precision, Quantizer, Serialized Form

Fields inherited from class ptolemy.data.ScalarToken
_unitCategoryExponents
 
Constructor Summary
FixToken(double value, int numberOfBits, int integerBits)
          Construct a FixToken representing the specified value with the specified precision.
FixToken(double value, Precision precision)
          Construct a FixToken representing the specified value with the specified precision.
FixToken(FixPoint value)
          Construct a FixToken with the supplied FixPoint value.
FixToken(java.lang.String init)
          Construct a FixToken from the specified string.
 
Method Summary
 ScalarToken absolute()
          Return a new FixToken containing the absolute value of this token.
 Token add(Token token)
          Return a new token whose value is the sum of this token and the argument.
 Token addReverse(Token token)
          Return a new token whose value is the sum of this token and the argument.
 double convertToDouble()
          Return the fixed point value of this token as a double.
 Token divide(Token divisor)
          Return a new Token whose value is the value of this token divided by the value of the argument token.
 Token divideReverse(Token dividend)
          Return a new token whose value is the value of the argument token divided by the value of this token.
 boolean equals(java.lang.Object object)
          Return true if the argument is an instance of FixToken with the same value.
 FixPoint fixValue()
          Return the value of this token as a FixPoint.
 Type getType()
          Return the type of this token.
 int hashCode()
          Return a hash code value for this token.
 BooleanToken isEqualTo(Token token)
          Test the values of this Token and the argument Token for equality.
 BooleanToken isLessThan(ScalarToken arg)
          Check whether the value of this token is strictly less than that of the argument token.
 Token multiply(Token token)
          Return a new token whose value is the product of this token and the argument.
 Token multiplyReverse(Token token)
          Return a new token whose value is the product of this token and the argument.
 Token one()
          Returns a new Token representing the multiplicative identity with the same precision as this FixToken.
 void print()
          Print the content of this FixToken: This is used for debugging only.
 Token subtract(Token rightArgument)
          Return a new Token whose value is the value of the argument token subtracted from the value of this token.
 Token subtractReverse(Token leftArgument)
          Return a new token whose value is the value of this token subtracted from the value of the argument token.
 java.lang.String toString()
          Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value.
 Token zero()
          Return a new token representing the additive identity with the same precision as this FixToken.
 
Methods inherited from class ptolemy.data.ScalarToken
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isUnitless, _subtractCategoryExponents, complexValue, doubleValue, intValue, inUnitsOf, longValue, setUnitCategory, unitsString
 
Methods inherited from class ptolemy.data.Token
_notSupportedMessage, convert, isCloseTo, isCloseTo, modulo, moduloReverse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixToken

public FixToken(FixPoint value)
Construct a FixToken with the supplied FixPoint value.
Parameters:
value - A FixPoint value.

FixToken

public FixToken(double value,
                Precision precision)
         throws java.lang.IllegalArgumentException
Construct a FixToken representing the specified value with the specified precision. The specified value is quantized to the closest value representable with the specified precision.
Parameters:
value - The value to represent.
precision - The precision to use.
Throws:
java.lang.IllegalArgumentException - If the supplied precision is invalid.

FixToken

public FixToken(double value,
                int numberOfBits,
                int integerBits)
         throws java.lang.IllegalArgumentException
Construct a FixToken representing the specified value with the specified precision. The specified value is quantized to the closest value representable with the specified precision.
Parameters:
value - The value to represent.
numberOfBits - The total number of bits.
integerBits - The number of integer bits.
Throws:
java.lang.IllegalArgumentException - If the supplied precision is invalid.

FixToken

public FixToken(java.lang.String init)
         throws IllegalActionException
Construct a FixToken from the specified string.
Parameters:
init - A string expression of a fixed point number in Ptolemy II expression language syntax.
Throws:
IllegalActionException - If the string does not contain a parsable fixed point number.
Method Detail

absolute

public ScalarToken absolute()
Return a new FixToken containing the absolute value of this token.
Overrides:
absolute in class ScalarToken
Returns:
A new instance of FixToken.

add

public Token add(Token token)
          throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. The type of the specified token must be lower than FixToken in the type lattice, meaning that it can be losslessly converted to an instance of FixToken.
Overrides:
add in class Token
Parameters:
token - The token to add to this one.
Returns:
A new token representing the sum.
Throws:
IllegalActionException - If the specified token is not of a type that can be added to this token.

addReverse

public Token addReverse(Token token)
                 throws IllegalActionException
Return a new token whose value is the sum of this token and the argument. The type of the specified token must be lower than FixToken in the type lattice, meaning that it can be losslessly converted to an instance of FixToken.
Overrides:
addReverse in class Token
Parameters:
token - The token to add this Token to.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the specified token is not of a type that can be added to this token.

convertToDouble

public double convertToDouble()
Return the fixed point value of this token as a double. The conversion from a fixed point to a double is not lossless, so the doubleValue() cannot be used. Therefore an explicit lossy conversion method is provided.
Returns:
A double representation of the value of this token.

divide

public Token divide(Token divisor)
             throws IllegalActionException
Return a new Token whose value is the value of this token divided by the value of the argument token. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
divide in class Token
Parameters:
divisor - A FixToken.
Returns:
A new FixToken.
Throws:
IllegalActionException - If the passed token is not of a type that can be divide this Tokens value by.

divideReverse

public Token divideReverse(Token dividend)
                    throws IllegalActionException
Return a new token whose value is the value of the argument token divided by the value of this token. The type of the specified token must be lower than FixToken.
Overrides:
divideReverse in class Token
Parameters:
dividend - The token to be divided by the value of this Token.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than FixToken.

equals

public boolean equals(java.lang.Object object)
Return true if the argument is an instance of FixToken with the same value.
Overrides:
equals in class Token
Parameters:
object - An instance of Object.
Returns:
True if the argument is an instance of FixToken with the same value.

fixValue

public FixPoint fixValue()
Return the value of this token as a FixPoint.
Overrides:
fixValue in class ScalarToken
Returns:
A FixPoint.

getType

public Type getType()
Return the type of this token.
Overrides:
getType in class ScalarToken
Returns:
BaseType.FIX.

hashCode

public int hashCode()
Return a hash code value for this token. This method returns the integer portion of the contained fixed point number.
Overrides:
hashCode in class Token
Returns:
A hash code value for this token.

isEqualTo

public BooleanToken isEqualTo(Token token)
                       throws IllegalActionException
Test the values of this Token and the argument Token for equality. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information.
Overrides:
isEqualTo in class Token
Parameters:
token - The token to test equality of this token with.
Returns:
BooleanToken indicating whether the values are equal.
Throws:
IllegalActionException - If the specified token is not of a type that can be compared with this Token.

isLessThan

public BooleanToken isLessThan(ScalarToken arg)
                        throws IllegalActionException
Check whether the value of this token is strictly less than that of the argument token.
Overrides:
isLessThan in class ScalarToken
Parameters:
arg - A ScalarToken.
Returns:
A BooleanToken with value true if this token is strictly less than the argument.
Throws:
IllegalActionException - If the type of the argument token is incomparable with the type of this token.

multiply

public Token multiply(Token token)
               throws IllegalActionException
Return a new token whose value is the product of this token and the argument. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
multiply in class Token
Parameters:
arg - A FixToken.
Returns:
A new FixToken.
Throws:
IllegalActionException - If the specified token is not of a type that can be multiplied to this Token.

multiplyReverse

public Token multiplyReverse(Token token)
                      throws IllegalActionException
Return a new token whose value is the product of this token and the argument. The type of the specified token must be lower than FixToken.
Overrides:
multiplyReverse in class Token
Parameters:
token - The token with which to multiply this Token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than FixToken.

one

public Token one()
Returns a new Token representing the multiplicative identity with the same precision as this FixToken.
Overrides:
one in class Token
Returns:
A new FixToken with value 1.0.

subtract

public Token subtract(Token rightArgument)
               throws IllegalActionException
Return a new Token whose value is the value of the argument token subtracted from the value of this token. The type of the specified token must be such that either it can be converted to the type of this token, or the type of this token can be converted to the type of the specified token, without loss of information. The type of the returned token is one of the above two types that allows lossless conversion from the other.
Overrides:
subtract in class Token
Parameters:
token - A FixToken.
Returns:
A new FixToken.
Throws:
IllegalActionException - If the specified token is not of a type that can be subtracted from this Token.

subtractReverse

public Token subtractReverse(Token leftArgument)
                      throws IllegalActionException
Return a new token whose value is the value of this token subtracted from the value of the argument token. The type of the specified token must be lower than FixToken.
Overrides:
subtractReverse in class Token
Parameters:
leftArgument - The token to subtract this token from.
Returns:
A new token containing the result.
Throws:
IllegalActionException - If the type of the specified token is not lower than FixToken;

toString

public java.lang.String toString()
Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value. The "fix" keyword indicates it is a FixToken. The first argument is the decimal value, the second is the total number of bits and the third is the number of bits for the integer portion. For more information about these arguments, see the three argument constructor.
Overrides:
toString in class Token
Returns:
A String representing of this Token.

zero

public Token zero()
Return a new token representing the additive identity with the same precision as this FixToken.
Overrides:
zero in class Token
Returns:
A new FixToken with value 0.0.

print

public void print()
Print the content of this FixToken: This is used for debugging only.