Package ptolemy.data

Class FixToken

    • Constructor Detail

      • FixToken

        public FixToken()
        Construct a token with integer 0. This method calls the FixPoint(int) constructor, so the precision and quantization are the what ever is defined for that constructor
      • 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

      • convert

        public static FixToken convert​(Token token)
                                throws IllegalActionException
        Convert the specified token into an instance of FixToken. 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 FixToken, it is returned without any change. Otherwise, if the argument is below FixToken in the type hierarchy, it is converted to an instance of FixToken or one of the subclasses of FixToken and returned. If none of the above conditions are met, an exception is thrown.
        Parameters:
        token - The token to be converted to a FixToken.
        Returns:
        A FixToken.
        Throws:
        IllegalActionException - If the conversion cannot be carried out.
      • 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.
      • equals

        public boolean equals​(java.lang.Object object)
        Return true if the argument's class is IntToken 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 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.
        Specified by:
        getType in class ScalarToken
        Returns:
        an instance of FixType;
      • hashCode

        public int hashCode()
        Return a hash code value for this value. This method returns the low order 32 bits of the integer representation.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this token.
      • 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.
      • print

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

        public final FixToken quantize​(Quantization quant)
        Return a new token whose value is constrained to comply with a quantization specification.
        Parameters:
        quant - The quantization specification.
        Returns:
        A new FixToken containing the result.
      • 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.
      • _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.
        Specified by:
        _absolute in class ScalarToken
        Returns:
        A FixToken.
      • _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 FixToken.
        Specified by:
        _add in class ScalarToken
        Parameters:
        rightArgument - The token to add to this token.
        Returns:
        A new FixToken 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:
        _bitwiseAnd in class ScalarToken
        Parameters:
        rightArgument - The FixToken to bitwise AND with this one.
        Returns:
        The bitwise AND.
        Throws:
        IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.
      • _bitwiseOr

        protected ScalarToken _bitwiseOr​(ScalarToken rightArgument)
                                  throws IllegalActionException
        Returns a token representing the bitwise OR of this token and the given token.
        Specified by:
        _bitwiseOr in class ScalarToken
        Parameters:
        rightArgument - The FixToken to bitwise OR with this one.
        Returns:
        The bitwise OR.
        Throws:
        IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.
      • _bitwiseXor

        protected ScalarToken _bitwiseXor​(ScalarToken rightArgument)
                                   throws IllegalActionException
        Returns a token representing the bitwise XOR of this token and the given token.
        Specified by:
        _bitwiseXor in class ScalarToken
        Parameters:
        rightArgument - The FixToken to bitwise XOR with this one.
        Returns:
        The bitwise XOR.
        Throws:
        IllegalActionException - If the given token is not compatible for this operation, or the operation does not make sense for this type.
      • _divide

        protected ScalarToken _divide​(ScalarToken rightArgument)
        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 FixToken
        Specified by:
        _divide in class ScalarToken
        Parameters:
        rightArgument - The token to divide this token by.
        Returns:
        A new FixToken containing the result.
      • _divide

        protected ScalarToken _divide​(ScalarToken rightArgument,
                                      Quantization quant)
        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 FixToken
        Parameters:
        rightArgument - The token to divide this token by.
        quant - The quantization specification.
        Returns:
        A new FixToken containing the result.
      • _isCloseTo

        protected BooleanToken _isCloseTo​(ScalarToken rightArgument,
                                          double epsilon)
        Test whether 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 FixToken. NOTE: Both the value of this token and the token to compare are converted to double using convertToDouble() before the comparison is made.
        Specified by:
        _isCloseTo in class ScalarToken
        Parameters:
        rightArgument - The token to compare to this token.
        epsilon - The value that we use to determine whether two tokens are close.
        Returns:
        A token containing true if the value of the first argument is close to the value of this token.
      • _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 FixToken.
        Specified by:
        _isLessThan in class ScalarToken
        Parameters:
        rightArgument - The token to add to this token.
        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)
                               throws IllegalActionException
        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 the same as the type of this class.
        Specified by:
        _modulo in class ScalarToken
        Parameters:
        rightArgument - The token to modulo this token by.
        Returns:
        A new Token containing the result that is of the same class as this token.
        Throws:
        IllegalActionException - If this method is not supported by the derived class.
      • _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 FixToken.
        Specified by:
        _multiply in class ScalarToken
        Parameters:
        rightArgument - The token to multiply this token by.
        Returns:
        A new FixToken containing the result.
      • _quantize

        protected FixToken _quantize​(Quantization quant)
        Return a new token whose value is constrained to comply with a quantization specification.
        Parameters:
        quant - The quantization specification.
        Returns:
        A new FixToken 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 FixToken.
        Specified by:
        _subtract in class ScalarToken
        Parameters:
        rightArgument - The token to subtract from this token.
        Returns:
        A new FixToken containing the result.