public abstract class ArithmeticEngine extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ArithmeticEngine.BigDecimalEngine
This is the default arithmetic engine in FreeMarker.
|
static class |
ArithmeticEngine.ConservativeEngine
An arithmetic engine that conservatively widens the operation arguments
to extent that they can hold the result of the operation.
|
Modifier and Type | Field and Description |
---|---|
static ArithmeticEngine.BigDecimalEngine |
BIGDECIMAL_ENGINE
Arithmetic engine that converts all numbers to
BigDecimal and
then operates on them. |
static ArithmeticEngine.ConservativeEngine |
CONSERVATIVE_ENGINE
Arithmetic engine that uses (more-or-less) the widening conversions of
Java language to determine the type of result of operation, instead of
converting everything to BigDecimal up front.
|
protected int |
maxScale |
protected int |
minScale |
protected int |
roundingPolicy |
Constructor and Description |
---|
ArithmeticEngine() |
Modifier and Type | Method and Description |
---|---|
abstract Number |
add(Number first,
Number second) |
abstract int |
compareNumbers(Number first,
Number second) |
abstract Number |
divide(Number first,
Number second) |
abstract Number |
modulus(Number first,
Number second) |
abstract Number |
multiply(Number first,
Number second) |
void |
setMaxScale(int maxScale)
Sets the maximal scale to use when multiplying BigDecimal numbers.
|
void |
setMinScale(int minScale)
Sets the minimal scale to use when dividing BigDecimal numbers.
|
void |
setRoundingPolicy(int roundingPolicy) |
abstract Number |
subtract(Number first,
Number second) |
abstract Number |
toNumber(String s)
Should be able to parse all FTL numerical literals, Java Double toString results, and XML Schema numbers.
|
public static final ArithmeticEngine.BigDecimalEngine BIGDECIMAL_ENGINE
BigDecimal
and
then operates on them. This is FreeMarker's default arithmetic engine.public static final ArithmeticEngine.ConservativeEngine CONSERVATIVE_ENGINE
protected int minScale
protected int maxScale
protected int roundingPolicy
public abstract int compareNumbers(Number first, Number second) throws TemplateException
TemplateException
public abstract Number add(Number first, Number second) throws TemplateException
TemplateException
public abstract Number subtract(Number first, Number second) throws TemplateException
TemplateException
public abstract Number multiply(Number first, Number second) throws TemplateException
TemplateException
public abstract Number divide(Number first, Number second) throws TemplateException
TemplateException
public abstract Number modulus(Number first, Number second) throws TemplateException
TemplateException
public abstract Number toNumber(String s)
-123.45
, 1.5e3
, 1.5E3
, 0005
, +0
, -0
, NaN
,
INF
, -INF
, Infinity
, -Infinity
.public void setMinScale(int minScale)
public void setMaxScale(int maxScale)
public void setRoundingPolicy(int roundingPolicy)