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.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ArithmeticEngine.ConservativeEngine
public ArithmeticEngine.ConservativeEngine()
compareNumbers
public int compareNumbers(Number first,
Number second)
throws TemplateException
- Specified by:
compareNumbers
in class ArithmeticEngine
- Throws:
TemplateException
add
public Number add(Number first,
Number second)
throws TemplateException
- Specified by:
add
in class ArithmeticEngine
- Throws:
TemplateException
subtract
public Number subtract(Number first,
Number second)
throws TemplateException
- Specified by:
subtract
in class ArithmeticEngine
- Throws:
TemplateException
multiply
public Number multiply(Number first,
Number second)
throws TemplateException
- Specified by:
multiply
in class ArithmeticEngine
- Throws:
TemplateException
divide
public Number divide(Number first,
Number second)
throws TemplateException
- Specified by:
divide
in class ArithmeticEngine
- Throws:
TemplateException
modulus
public Number modulus(Number first,
Number second)
throws TemplateException
- Specified by:
modulus
in class ArithmeticEngine
- Throws:
TemplateException
toNumber
public Number toNumber(String s)
- Specified by:
toNumber
in class ArithmeticEngine