Package ptolemy.data

Class DoubleToken

  • All Implemented Interfaces:
    BitwiseOperationToken, PartiallyOrderedToken
    Direct Known Subclasses:
    SmoothToken

    public class DoubleToken
    extends ScalarToken
    A token that contains a 64-bit signed mantissa, signed exponent double precision floating-point number (IEEE 754). This class handles overflow and underflow as does normal java arithmetic on doubles.

    Note that a double cannot be losslessly converted to a long, and vice versa, as both have 64-bit representations in Java.

    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Neil Smyth, Yuhong Xiong, Christopher Hylands, Steve Neuendorffer
    See Also:
    Token
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (cxh) nil token, ONE, ZERO
    • Field Detail

      • NIL

        public static final DoubleToken NIL
        A token that represents a missing value. Null or missing tokens are common in analytical systems like R and SAS where they are used to handle sparsely populated data sources. In database parlance, missing tokens are sometimes called null tokens. Since null is a Java keyword, we use the term "nil". The toString() method on a nil token returns the string "nil".
      • ONE

        public static final DoubleToken ONE
        A DoubleToken with the value 1.0.
      • ZERO

        public static final DoubleToken ZERO
        A DoubleToken with the value 0.0.
      • _value

        protected double _value
        The double value. Derived constructors may set this variable, but after it is set in the constructor it should not be modified.
    • Constructor Detail

      • DoubleToken

        public DoubleToken()
        Construct a DoubleToken with value 0.0.
      • DoubleToken

        public DoubleToken​(double value)
        Construct a DoubleToken with the specified value.
        Parameters:
        value - The specified value.
      • DoubleToken

        public DoubleToken​(java.lang.String init)
                    throws IllegalActionException
        Construct a DoubleToken from the specified string.
        Parameters:
        init - The initialization string, which is in a format suitable for java.lang.Double.parseDouble(String).
        Throws:
        IllegalActionException - If the Token could not be created with the given String.
    • Method Detail

      • complexValue

        public Complex complexValue()
        Return the value of this token as a Complex. The real part of the Complex is the value of this token, the imaginary part is set to 0.
        Overrides:
        complexValue in class ScalarToken
        Returns:
        A Complex
      • convert

        public static DoubleToken convert​(Token token)
                                   throws IllegalActionException
        Convert the specified token into an instance of DoubleToken. 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 DoubleToken, it is returned without any change. If it is a PetiteToken is it returned as a DoubleToken since lossless conversion is possible between PetiteToken and DoubleToken. If the argument is a nil token, then NIL is returned. Otherwise, if the argument is below DoubleToken in the type hierarchy, it is converted to an instance of DoubleToken or one of the subclasses of DoubleToken and returned. If none of the above condition is met, an exception is thrown.
        Parameters:
        token - The token to be converted to a DoubleToken.
        Returns:
        A DoubleToken.
        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.
      • equals

        public boolean equals​(java.lang.Object object)
        Return true if the argument's class is DoubleToken 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 DoubleToken with the same value. If either this object or the argument is a nil Token, return false.
      • getType

        public Type getType()
        Return the type of this token.
        Specified by:
        getType in class ScalarToken
        Returns:
        BaseType.DOUBLE
      • hashCode

        public int hashCode()
        Return a hash code value for this token. This method returns the integer portion of the contained double.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this token.
      • isNil

        public boolean isNil()
        Return true if the token is nil, (aka null or missing). Nil or missing tokens occur when a data source is sparsely populated.
        Overrides:
        isNil in class Token
        Returns:
        True if the token is the NIL token.
      • one

        public Token one()
        Returns a DoubleToken with value 1.0.
        Overrides:
        one in class Token
        Returns:
        A DoubleToken with value 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 DoubleToken with value 0.0.
        Overrides:
        zero in class Token
        Returns:
        A DoubleToken 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:
        An DoubleToken.
      • _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 DoubleToken.
        Specified by:
        _add in class ScalarToken
        Parameters:
        rightArgument - The token to add to this token.
        Returns:
        A new DoubleToken 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 DoubleToken
        Specified by:
        _divide in class ScalarToken
        Parameters:
        divisor - The token to divide this token by.
        Returns:
        A new DoubleToken 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 DoubleToken.
        Specified by:
        _isCloseTo in class ScalarToken
        Parameters:
        rightArgument - The token to compare to this token.
        epsilon - The distance.
        Returns:
        A token containing tue 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 DoubleToken.
        Specified by:
        _isLessThan in class ScalarToken
        Parameters:
        rightArgument - The token to compare 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)
        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 DoubleToken.
        Specified by:
        _modulo in class ScalarToken
        Parameters:
        rightArgument - The token to modulo this token by.
        Returns:
        A new DoubleToken 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 DoubleToken.
        Specified by:
        _multiply in class ScalarToken
        Parameters:
        rightArgument - The token to multiply this token by.
        Returns:
        A new DoubleToken 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 DoubleToken.
        Specified by:
        _subtract in class ScalarToken
        Parameters:
        rightArgument - The token to subtract from this token.
        Returns:
        A new DoubleToken containing the result.