Package freemarker.core
Class ArithmeticEngine.ConservativeEngine
- java.lang.Object
-
- freemarker.core.ArithmeticEngine
-
- freemarker.core.ArithmeticEngine.ConservativeEngine
-
- Enclosing class:
- ArithmeticEngine
public static class ArithmeticEngine.ConservativeEngine extends ArithmeticEngine
An arithmetic engine that conservatively widens the operation arguments to extent that they can hold the result of the operation. Widening conversions occur in following situations:- byte and short are always widened to int (alike to Java language).
- To preserve magnitude: when operands are of different types, the result type is the type of the wider operand.
- to avoid overflows: if add, subtract, or multiply would overflow on integer types, the result is widened from int to long, or from long to BigInteger.
- to preserve fractional part: if a division of integer types would have a fractional part, int and long are converted to double, and BigInteger is converted to BigDecimal. An operation on a float and a long results in a double. An operation on a float or double and a BigInteger results in a BigDecimal.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class freemarker.core.ArithmeticEngine
ArithmeticEngine.BigDecimalEngine, ArithmeticEngine.ConservativeEngine
-
-
Field Summary
-
Fields inherited from class freemarker.core.ArithmeticEngine
BIGDECIMAL_ENGINE, CONSERVATIVE_ENGINE, maxScale, minScale, roundingPolicy
-
-
Constructor Summary
Constructors Constructor Description ConservativeEngine()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Number
add(java.lang.Number first, java.lang.Number second)
int
compareNumbers(java.lang.Number first, java.lang.Number second)
java.lang.Number
divide(java.lang.Number first, java.lang.Number second)
java.lang.Number
modulus(java.lang.Number first, java.lang.Number second)
java.lang.Number
multiply(java.lang.Number first, java.lang.Number second)
java.lang.Number
subtract(java.lang.Number first, java.lang.Number second)
java.lang.Number
toNumber(java.lang.String s)
Should be able to parse all FTL numerical literals, Java Double toString results, and XML Schema numbers.-
Methods inherited from class freemarker.core.ArithmeticEngine
setMaxScale, setMinScale, setRoundingPolicy
-
-
-
-
Method Detail
-
compareNumbers
public int compareNumbers(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
compareNumbers
in classArithmeticEngine
- Throws:
TemplateException
-
add
public java.lang.Number add(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
add
in classArithmeticEngine
- Throws:
TemplateException
-
subtract
public java.lang.Number subtract(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
subtract
in classArithmeticEngine
- Throws:
TemplateException
-
multiply
public java.lang.Number multiply(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
multiply
in classArithmeticEngine
- Throws:
TemplateException
-
divide
public java.lang.Number divide(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
divide
in classArithmeticEngine
- Throws:
TemplateException
-
modulus
public java.lang.Number modulus(java.lang.Number first, java.lang.Number second) throws TemplateException
- Specified by:
modulus
in classArithmeticEngine
- Throws:
TemplateException
-
toNumber
public java.lang.Number toNumber(java.lang.String s)
Description copied from class:ArithmeticEngine
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
.- Specified by:
toNumber
in classArithmeticEngine
-
-