|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.math.Quantizer
public class Quantizer
This class provides a set of static methods for creating instances of the FixPoint class from doubles, integers, or fixed point numbers. The various round() methods return a fixed point value that is nearest to the specified number, but has the specified precision. The various roundToZero() and truncate() methods return a fixed point value that is nearest to the specified number, but no greater in magnitude. The various roundDown() methods return a the nearest fixed point less than the argument. The intention is to fill out this class with roundUp(), and roundNearestEven(). All of these methods may introduce quantization errors and/or overflow. This class has been reimplemented to perform all rounding by first constructing a FixPointQuantization and then using either the quantizing constructor of FixPoint or FixPoint.quantize. Users may find that their code simplifies if they do likewise.
FixPoint
,
Overflow
,
Precision
,
Rounding
,
Quantization
Red (kienhuis) |
Yellow (kienhuis) |
Field Summary | |
---|---|
static Overflow |
OVERFLOW_TO_ZERO
Indicate that overflow should result in a zero value. |
static Overflow |
SATURATE
Indicate that overflow should saturate. |
Constructor Summary | |
---|---|
private |
Quantizer()
|
Method Summary | |
---|---|
static FixPoint |
round(java.math.BigDecimal value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
round(double value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
round(FixPoint value,
Precision newPrecision,
Overflow mode)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundDown(java.math.BigDecimal value,
Precision precision)
Return the nearest fixed point number with less than or equal magnitude that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundDown(double value,
Precision precision)
Return the nearest fixed point number with less than or equal magnitude that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundDown(FixPoint value,
Precision newPrecision,
Overflow mode)
Return the nearest fixed point number with less than or equal magnitude that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundNearestEven(java.math.BigDecimal value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundNearestEven(double value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundNearestEven(FixPoint value,
Precision newPrecision,
Overflow mode)
Return the fixed point number that is nearest to the specified value, but has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundToZero(java.math.BigDecimal value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has magnitude no greater that the specified value, and has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundToZero(double value,
Precision precision)
Return the fixed point number that is nearest to the specified value, but has magnitude no greater that the specified value, and has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundToZero(FixPoint value,
Precision newPrecision,
Overflow mode)
Return the fixed point number that is nearest to the specified value, but has magnitude no greater than the specified value, and has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundUp(java.math.BigDecimal value,
Precision precision)
Return the smallest greater than or equal fixed point number that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundUp(double value,
Precision precision)
Return the smallest greater than or equal fixed point number that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
roundUp(FixPoint value,
Precision newPrecision,
Overflow mode)
Return the smallest greater than or equal fixed point number that has the given precision, possibly introducing quantization or overflow errors. |
static FixPoint |
truncate(java.math.BigDecimal value,
Precision precision)
Deprecated. Use roundToZero instead. |
static FixPoint |
truncate(double value,
Precision precision)
Deprecated. Use roundToZero instead. |
static FixPoint |
truncate(FixPoint value,
Precision newPrecision,
Overflow mode)
Deprecated. Use roundToZero instead. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Overflow SATURATE
public static final Overflow OVERFLOW_TO_ZERO
Constructor Detail |
---|
private Quantizer()
Method Detail |
---|
public static FixPoint round(double value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint round(java.math.BigDecimal value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint round(FixPoint value, Precision newPrecision, Overflow mode)
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
public static FixPoint roundDown(double value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundDown(java.math.BigDecimal value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundDown(FixPoint value, Precision newPrecision, Overflow mode)
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
public static FixPoint roundNearestEven(double value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundNearestEven(java.math.BigDecimal value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundNearestEven(FixPoint value, Precision newPrecision, Overflow mode)
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
public static FixPoint roundToZero(double value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundToZero(java.math.BigDecimal value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundToZero(FixPoint value, Precision newPrecision, Overflow mode)
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
public static FixPoint roundUp(double value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundUp(java.math.BigDecimal value, Precision precision)
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint roundUp(FixPoint value, Precision newPrecision, Overflow mode)
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
public static FixPoint truncate(double value, Precision precision)
Note: This method does NOT perform truncation per most fixed-point DSP implementations, which simply drop the fractional bits. Most models of fixed-point algorithms will use the roundDown methods in this class instead.
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint truncate(java.math.BigDecimal value, Precision precision)
Note: This method does NOT perform truncation per most fixed-point DSP implementations, which simply drop the fractional bits. Most models of fixed-point algorithms will use the roundDown methods in this class instead.
value
- The value to represent.precision
- The precision of the representation.
public static FixPoint truncate(FixPoint value, Precision newPrecision, Overflow mode)
Note: This method does NOT perform truncation per most fixed-point DSP implementations, which simply drop the fractional bits. Most models of fixed-point algorithms will use the roundDown methods in this class instead.
value
- The value to represent.newPrecision
- The precision of the representation.mode
- The overflow mode.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |