Package freemarker.core
Class ArithmeticEngine
java.lang.Object
freemarker.core.ArithmeticEngine
- Direct Known Subclasses:
ArithmeticEngine.BigDecimalEngine
,ArithmeticEngine.ConservativeEngine
Used for implementing the arithmetic operations and number comparisons in the template language. The concrete
implementation is plugged into the configuration with the
arithmetical_engine
setting.
(See Configurable.setArithmeticEngine(ArithmeticEngine)
.)-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This is the default arithmetic engine in FreeMarker.static class
An arithmetic engine that conservatively widens the operation arguments to extent that they can hold the result of the operation. -
Field Summary
Modifier and TypeFieldDescriptionArithmetic engine that converts all numbers toBigDecimal
and then operates on them, and also keeps the result as aBigDecimal
.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
protected int
protected int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Number
abstract int
compareNumbers(Number first, Number second)
abstract Number
abstract Number
abstract Number
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
abstract Number
Should be able to parse all FTL numerical literals, Java Double toString results, and XML Schema numbers.
-
Field Details
-
BIGDECIMAL_ENGINE
Arithmetic engine that converts all numbers toBigDecimal
and then operates on them, and also keeps the result as aBigDecimal
. This is FreeMarker's default arithmetic engine. -
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. -
minScale
protected int minScale -
maxScale
protected int maxScale -
roundingPolicy
protected int roundingPolicy
-
-
Constructor Details
-
ArithmeticEngine
public ArithmeticEngine()
-
-
Method Details
-
compareNumbers
- Throws:
TemplateException
-
add
- Throws:
TemplateException
-
subtract
- Throws:
TemplateException
-
multiply
- Throws:
TemplateException
-
divide
- Throws:
TemplateException
-
modulus
- Throws:
TemplateException
-
toNumber
Should be able to parse all FTL numerical literals, Java Double toString results, and XML Schema numbers. This means these should be parsed successfully, except if the arithmetical engine couldn't support the resulting value anyway (such as NaN, infinite, even non-integers):-123.45
,1.5e3
,1.5E3
,0005
,+0
,-0
,NaN
,INF
,-INF
,Infinity
,-Infinity
. -
setMinScale
public void setMinScale(int minScale)Sets the minimal scale to use when dividing BigDecimal numbers. Default value is 12. -
setMaxScale
public void setMaxScale(int maxScale)Sets the maximal scale to use when multiplying BigDecimal numbers. Default value is 100. -
setRoundingPolicy
public void setRoundingPolicy(int roundingPolicy)
-