ptolemy.data.expr
Class FixPointFunctions

java.lang.Object
  extended by ptolemy.data.expr.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

In all cases, rounding is used when quantization errors occur, and saturation is used when overflow occurs.

Since:
Ptolemy II 0.4
Version:
$Id: FixPointFunctions.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Bart Kienhuis, Contributor: Edward A. Lee
See Also:
PtParser, FixPoint, Quantizer
Accepted Rating:
Red (kienhuis)
Proposed Rating:
Yellow (kienhuis)

Constructor Summary
private FixPointFunctions()
           
 
Method Summary
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
 

Constructor Detail

FixPointFunctions

private FixPointFunctions()
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.