Numerical operators try to treat their arguments as numbers. The basic primitive-type wrapper classes (Integer, Double, and so on, including Character and Boolean, which are treated as integers), and the "big" numeric classes from the java.math package (BigInteger and BigDecimal), are recognized as special numeric types. Given an object of some other class, OGNL tries to parse the object's string value as a number.
Numerical operators that take two arguments use the following algorithm to decide what type the result should be. The type of the actual result may be wider, if the result does not fit in the given type.
If both arguments are of the same type, the result will be of the same type if possible.
If either argument is not of a recognized numeric class, it will be treated as if it was a Double
for the rest of this algorithm.
If both arguments are approximations to real numbers (Float
, Double
, or BigDecimal
), the result will be the wider type.
If both arguments are integers (Boolean
, Byte
, Character
, Short
, Integer
, Long
, or
BigInteger
), the result will be the wider type.
If one argument is a real type and the other an integer type, the result will be the real type if the integer is narrower than "int"; BigDecimal
if the integer is BigInteger
;
or the wider of the real type and Double
otherwise.