Class FixPointFunctions


  • public class FixPointFunctions
    extends java.lang.Object
    This class provides static functions for operating on Fixpoint numbers in the Ptolemy II expression language. The added functionality is
    • Create a FixPoint for a double value with a particular precision. The result is an instance of FixPoint. For example:
       fix(5.34, 10, 4)
       
      creates a fixed point number with a total of 10 bits, 4 of which are integer bits, representing the number 5.34.
    • Create a FixPointMatrix with entries that consist of instances of FixPoint. Each entry in the fixed point matrix has the same precision. For example,
       fix([ -.040609, -.001628, .17853, .37665, .37665, .17853,
       -.001628, -.040609 ], 10, 2)
       
      creates a matrix where each entry has 10 bits, two of which are integer bits.
    • Create a DoubleToken whose value is the quantized version of the given double value. The value is quantized by converting it into a fixed point value with a particular precision and then back again to a double value. For example,
       quantize(5.34, 10, 4)
       
      quantizes the number 5.34 to 10 bits of precision, 4 of which are integer bits.
    • Create a matrix whose entries are the quantized version of the values of the given matrix. The values are quantized by converting them into a fixed point value with a particular precision and then back again into a double value. Each entry is quantized using the same precision. The result is an instance of DoubleMatrixToken. For example:
       quantize([ -.040609, -.001628, .17853, .37665, .37665, .17853,
       -.001628, -.040609 ], 10, 2)
       
      creates a new instance of DoubleMatrixToken containing the specified values with 10 bits of precision, two of which are integer bits.
    In all cases, rounding is used when quantization errors occur, and saturation is used when overflow occurs.
    Since:
    Ptolemy II 0.4
    Version:
    $Id$
    Author:
    Bart Kienhuis, Contributor: Edward A. Lee
    See Also:
    PtParser, FixPoint, Quantizer
    Pt.AcceptedRating:
    Red (kienhuis)
    Pt.ProposedRating:
    Yellow (kienhuis)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static FixPoint fix​(double value, int numberOfBits, int integerBits)
      Create a FixPoint representing the specified double.
      static FixPoint fix​(int value, int numberOfBits, int integerBits)
      Create a FixPoint representing the specified integer.
      static double quantize​(double value, int numberOfBits, int integerBits)
      Create a double whose value is the quantized version of the given double value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • fix

        public static FixPoint fix​(int value,
                                   int numberOfBits,
                                   int integerBits)
        Create a FixPoint representing the specified integer. For example,
              fix(5, 10, 4)
          
        creates a fixed point representation of the integer 5 with 10 bits of precision, 4 of which are integer bits.
        Parameters:
        value - The value to represent.
        numberOfBits - The total number of bits.
        integerBits - The number of bits used for the integer part.
        Returns:
        A fixed point representation of the value.
      • fix

        public static FixPoint fix​(double value,
                                   int numberOfBits,
                                   int integerBits)
        Create a FixPoint representing the specified double. For example,
              fix(5.34, 10, 4)
          
        creates a fixed point representation of the numer 5.34 with 10 bits of precision, 4 of which are integer bits.
        Parameters:
        value - The value to represent.
        numberOfBits - The total number of bits.
        integerBits - The number of bits used for the integer part.
        Returns:
        A fixed point representation of the value.
      • quantize

        public static double quantize​(double value,
                                      int numberOfBits,
                                      int integerBits)
        Create a double whose value is the quantized version of the given double value. The value is quantized by converting it into a fixed point value with a particular precision and then back again into a double value. For example,
             quantize(5.34, 10, 4)
          
        yields a double representing 5.34 quantized to 10 bits of precision, of which 4 bits are used for the integer part and 6 bits are used for the fractional part.
        Parameters:
        value - The value to quantize.
        numberOfBits - The total number of bits.
        integerBits - The number of bits used for the integer part.
        Returns:
        a double with value that is quantized.