Package ptolemy.data

Class 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 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 IllegalActionException
        Construct a PetiteToken from the specified string.Ensure the value is adjusted within the range of a PetiteToken.
        Parameters:
        init - The specified string, for example 1.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:
        doubleValue in class ScalarToken
        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:
        equals in class java.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:
        getType in class ScalarToken
        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:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this token.
      • one

        public Token one()
        Returns a PetiteToken with value nearest 1.0.......
        Overrides:
        one in class Token
        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 use Double.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:
        toString in class Token
        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.
        Overrides:
        zero in class Token
        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:
        _absolute in class ScalarToken
        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:
        _add in class ScalarToken
        Parameters:
        rightArgument - The token to add to this token.
        Returns:
        A new PetiteToken containing the result.
      • _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:
        _divide in class ScalarToken
        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:
        _isCloseTo in class ScalarToken
        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:
        _isLessThan in class ScalarToken
        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:
        _modulo in class ScalarToken
        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:
        _multiply in class ScalarToken
        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:
        _subtract in class ScalarToken
        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.