Package ptolemy.data
Class PetiteToken
- java.lang.Object
-
- ptolemy.data.Token
-
- ptolemy.data.ScalarToken
-
- ptolemy.data.PetiteToken
-
- All Implemented Interfaces:
BitwiseOperationToken,PartiallyOrderedToken
public class PetiteToken extends ScalarToken
A token that contains a number which is essentially a simulation equivalent for fixed point numbers in embedded processors. By definition it is between -1 (inclusive) and 1 (exclusive). It is a extension of the Double Token and maintains the same precision as Double Token.- Since:
- Ptolemy II 5.2
- Version:
- $Id$
- Author:
- Shamik Bandyopadhyay
- See Also:
Token- Pt.AcceptedRating:
- Green (cxh)
- Pt.ProposedRating:
- Green (neuendor)
-
-
Field Summary
Fields Modifier and Type Field Description static PetiteTokenONEA PetiteToken with the value 1.0.static PetiteTokenZEROA PetiteToken with the value 0.0.-
Fields inherited from class ptolemy.data.ScalarToken
_unitCategoryExponents
-
-
Constructor Summary
Constructors Constructor Description PetiteToken()Construct a PetiteToken with value 0.0.PetiteToken(double value)Construct a PetiteToken with the specified value.PetiteToken(java.lang.String init)Construct a PetiteToken from the specified string.Ensure the value is adjusted within the range of a PetiteToken.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ScalarToken_absolute()Return a ScalarToken containing the absolute value of the value of this token.protected ScalarToken_add(ScalarToken rightArgument)Return a new token whose value is the value of the argument Token added to the value of this Token.protected static double_adjust(double number)Adjust the value of the PetiteToken to limit it to the range [-1,1) while maintaining the precision of PetiteToken.protected ScalarToken_bitwiseAnd(ScalarToken rightArgument)Returns a token representing the bitwise AND of this token and the given token.protected ScalarToken_bitwiseNot()Returns a token representing the bitwise NOT of this token.protected ScalarToken_bitwiseOr(ScalarToken rightArgument)Returns a token representing the bitwise OR of this token and the given token.protected ScalarToken_bitwiseXor(ScalarToken rightArgument)Returns a token representing the bitwise XOR of this token and the given token.protected ScalarToken_divide(ScalarToken divisor)Return a new token whose value is the value of this token divided by the value of the argument token.protected BooleanToken_isCloseTo(ScalarToken rightArgument, double epsilon)Test that the value of this token is close to the first argument, where "close" means that the distance between their values is less than or equal to the second argument.protected BooleanToken_isLessThan(ScalarToken rightArgument)Test for ordering of the values of this Token and the argument Token.protected ScalarToken_modulo(ScalarToken rightArgument)Return a new token whose value is the value of this token modulo the value of the argument token.protected ScalarToken_multiply(ScalarToken rightArgument)Return a new token whose value is the value of this token multiplied by the value of the argument token.protected ScalarToken_subtract(ScalarToken rightArgument)Return a new token whose value is the value of the argument token subtracted from the value of this token.static PetiteTokenconvert(Token token)Convert the specified token into an instance of PetiteToken.doubledoubleValue()Return the value in the token as a double.booleanequals(java.lang.Object object)Return true if the argument's class is PetiteToken and it has the same values as this token.TypegetType()Return the type of this token.inthashCode()Return a hash code value for this token.Tokenone()Returns a PetiteToken with value nearest 1.0.......doublepetiteValue()Return the value in the token.java.lang.StringtoString()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.Tokenzero()Returns a PetiteToken with value 0.0.-
Methods inherited from class ptolemy.data.ScalarToken
_addCategoryExponents, _areUnitsEqual, _copyOfCategoryExponents, _isEqualTo, _isUnitless, _subtractCategoryExponents, absolute, add, addReverse, bitwiseAnd, bitwiseNot, bitwiseOr, bitwiseXor, byteValue, complexValue, divide, divideReverse, fixValue, floatValue, intValue, inUnitsOf, isCloseTo, isEqualTo, isGreaterThan, isLessThan, isLessThan, leftShift, logicalRightShift, longValue, modulo, moduloReverse, multiply, multiplyReverse, rightShift, setUnitCategory, shortValue, subtract, subtractReverse, unitsString
-
Methods inherited from class ptolemy.data.Token
isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
-
-
-
-
Field Detail
-
ONE
public static final PetiteToken ONE
A PetiteToken with the value 1.0.
-
ZERO
public static final PetiteToken ZERO
A PetiteToken with the value 0.0.
-
-
Constructor Detail
-
PetiteToken
public PetiteToken()
Construct a PetiteToken with value 0.0.
-
PetiteToken
public PetiteToken(double value)
Construct a PetiteToken with the specified value. Ensure that the value is adjusted within limits [-1,1).- Parameters:
value- The specified value.
-
PetiteToken
public PetiteToken(java.lang.String init) throws IllegalActionExceptionConstruct a PetiteToken from the specified string.Ensure the value is adjusted within the range of a PetiteToken.- Parameters:
init- The specified string, for example1.0p- Throws:
IllegalActionException- If the Token could not be created with the given String.
-
-
Method Detail
-
convert
public static PetiteToken convert(Token token) throws IllegalActionException
Convert the specified token into an instance of PetiteToken. This method does lossless conversion. The units of the returned token will be the same as the units of the given token. If the argument is already an instance of PetiteToken, it is returned without any change. Since the PetiteToken is cannot be losslessly converted to any other token an exception is thrown, in all other cases.- Parameters:
token- The token to be converted to a PetiteToken.- Returns:
- A PetiteToken.
- Throws:
IllegalActionException- If the conversion cannot be carried out.
-
doubleValue
public double doubleValue()
Return the value in the token as a double.- Overrides:
doubleValuein classScalarToken- Returns:
- The value contained in this token as a double.
-
petiteValue
public double petiteValue()
Return the value in the token.- Returns:
- The value contained in this token.
-
equals
public boolean equals(java.lang.Object object)
Return true if the argument's class is PetiteToken and it has the same values as this token.- Overrides:
equalsin classjava.lang.Object- Parameters:
object- An instance of Object.- Returns:
- True if the argument is a PetiteToken with the same value.
-
getType
public Type getType()
Return the type of this token.- Specified by:
getTypein classScalarToken- Returns:
- BaseType.PETITE
-
hashCode
public int hashCode()
Return a hash code value for this token. This method returns the hash code of the contained double.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A hash code value for this token.
-
one
public Token one()
Returns a PetiteToken with value nearest 1.0.......
-
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 exact form of the number depends on its value, and may be either decimal or exponential. In general, exponential is used for numbers whose magnitudes are very large or very small, except for zero which is always represented as 0.0. The behavior is roughly the same as Double.toString(), except that we limit the precision to seven fractional digits. If you really must have better precision, then useDouble.toString(token.doubleValue()). If this token has a unit, the return string also includes a unit string produced by the unitsString() method in the super class.- Overrides:
toStringin classToken- Returns:
- A String representing the double value and the units (if any) of this token.
- See Also:
ScalarToken.unitsString()
-
zero
public Token zero()
Returns a PetiteToken with value 0.0.
-
_absolute
protected ScalarToken _absolute()
Return a ScalarToken containing the absolute value of the value of this token. If this token contains a non-negative number, it is returned directly; otherwise, a new token is is return. Note that it is explicitly allowable to return this token, since the units are the same. The call to the constructor ensures the value is within the range defined by a PetiteToken. It thus automatically converts -1 to (1 - Double.MIN_VALUE).- Specified by:
_absolutein classScalarToken- Returns:
- An PetiteToken.
-
_add
protected ScalarToken _add(ScalarToken rightArgument)
Return a new token whose value is the value of the argument Token added to the value of this Token. It is assumed that the type of the argument is an PetiteToken.The token to add is first adjusted to the range defined by a petite token. After division, the result is adjusted again to maintain the range of a PetiteToken. The final adjustment happens automatically given the call to _adjust in the PetiteToken constructor.- Specified by:
_addin classScalarToken- Parameters:
rightArgument- The token to add to this token.- Returns:
- A new PetiteToken containing the result.
-
_bitwiseAnd
protected ScalarToken _bitwiseAnd(ScalarToken rightArgument) throws IllegalActionException
Returns a token representing the bitwise AND of this token and the given token.- Specified by:
_bitwiseAndin classScalarToken- Parameters:
rightArgument- The PetiteToken to bitwise AND with this one.- Returns:
- The bitwise AND.
- Throws:
IllegalActionException- Always thrown by this base class.
-
_bitwiseNot
protected ScalarToken _bitwiseNot() throws IllegalActionException
Returns a token representing the bitwise NOT of this token.- Specified by:
_bitwiseNotin classScalarToken- Returns:
- The bitwise NOT of this token.
- Throws:
IllegalActionException- Always thrown by this base class.
-
_bitwiseOr
protected ScalarToken _bitwiseOr(ScalarToken rightArgument) throws IllegalActionException
Returns a token representing the bitwise OR of this token and the given token.- Specified by:
_bitwiseOrin classScalarToken- Parameters:
rightArgument- The PetiteToken to bitwise OR with this one.- Returns:
- The bitwise OR.
- Throws:
IllegalActionException- Always thrown by this base class.
-
_bitwiseXor
protected ScalarToken _bitwiseXor(ScalarToken rightArgument) throws IllegalActionException
Returns a token representing the bitwise XOR of this token and the given token.- Specified by:
_bitwiseXorin classScalarToken- Parameters:
rightArgument- The PetiteToken to bitwise XOR with this one.- Returns:
- The bitwise XOR.
- Throws:
IllegalActionException- Always thrown by this base class.
-
_divide
protected ScalarToken _divide(ScalarToken divisor)
Return a new token whose value is the value of this token divided by the value of the argument token. It is assumed that the type of the argument is an PetiteToken. The token to divide by is first adjusted to the range defined by a petite token. After division, the result is adjusted again to maintain the range of a PetiteToken. The final adjustment happens automatically given the call to _adjust in the PetiteToken constructor.- Specified by:
_dividein classScalarToken- Parameters:
divisor- The token to divide this token by.- Returns:
- A new PetiteToken containing the result.
-
_isCloseTo
protected BooleanToken _isCloseTo(ScalarToken rightArgument, double epsilon)
Test that the value of this token is close to the first argument, where "close" means that the distance between their values is less than or equal to the second argument. It is assumed that the type of the first argument is PetiteToken. The right argument is adjusted to be in the range of a PetiteToken. The second argument is also adjusted likewise.- Specified by:
_isCloseToin classScalarToken- Parameters:
rightArgument- The token to compare to this token.epsilon- The distance.- Returns:
- A token containing true if the value of this token is close to that of the argument.
-
_isLessThan
protected BooleanToken _isLessThan(ScalarToken rightArgument) throws IllegalActionException
Test for ordering of the values of this Token and the argument Token. It is assumed that the type of the argument is PetiteToken. The argument token is then adjusted to the range of a PetiteToken.- Specified by:
_isLessThanin classScalarToken- Parameters:
rightArgument- The token to compare this token with.- Returns:
- A new Token containing the result.
- Throws:
IllegalActionException- If this method is not supported by the derived class.
-
_modulo
protected ScalarToken _modulo(ScalarToken rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token. It is assumed that the type of the argument is an PetiteToken.The token to take modulo by is first adjusted to the range defined by a petite token. After the modulo operation, the result is adjusted again to maintain the range of a PetiteToken. The final adjustment happens automatically given the call to _adjust in the PetiteToken constructor- Specified by:
_moduloin classScalarToken- Parameters:
rightArgument- The token to modulo this token by.- Returns:
- A new PetiteToken containing the result.
-
_multiply
protected ScalarToken _multiply(ScalarToken rightArgument)
Return a new token whose value is the value of this token multiplied by the value of the argument token. It is assumed that the type of the argument is an PetiteToken.The token to multiply is first adjusted to the range defined by a petite token. After multiplication, the result is adjusted again to maintain the range of a PetiteToken. The final adjustment happens automatically given the call to _adjust in the PetiteToken constructor- Specified by:
_multiplyin classScalarToken- Parameters:
rightArgument- The token to multiply this token by.- Returns:
- A new PetiteToken containing the result.
-
_subtract
protected ScalarToken _subtract(ScalarToken rightArgument)
Return a new token whose value is the value of the argument token subtracted from the value of this token. It is assumed that the type of the argument is an PetiteToken. The token to subtract is first adjusted to the range defined by a petite token. After subtraction from this token, the result is adjusted again to maintain the range of a PetiteToken. The final adjustment happens automatically given the call to _adjust in the PetiteToken constructor- Specified by:
_subtractin classScalarToken- Parameters:
rightArgument- The token to subtract from this token.- Returns:
- A new PetiteToken containing the result.
-
_adjust
protected static double _adjust(double number)
Adjust the value of the PetiteToken to limit it to the range [-1,1) while maintaining the precision of PetiteToken.- Parameters:
number- The value to be adjusted.- Returns:
- The adjusted value.
-
-