throw new XPathException(this, ErrorCodes.FORG0006,
Type.getTypeName(value.getType()) + "(" + value + ") " +
"can not be an operand in a sum", value);
}
//Set the first value
ComputableValue sum = (ComputableValue) value;
while (iter.hasNext()) {
item = iter.nextItem();
value = item.atomize();
//Any value of type xdt:untypedAtomic are cast to xs:double
if (value.getType() == Type.UNTYPED_ATOMIC)
{value = value.convertTo(Type.DOUBLE);}
if (!(value instanceof ComputableValue)) {
throw new XPathException(this, ErrorCodes.FORG0006, "" +
Type.getTypeName(value.getType()) + "(" + value +
") can not be an operand in a sum", value);
}
if (Type.subTypeOf(value.getType(), Type.NUMBER)) {
if (((NumericValue)value).isInfinite())
{gotInfinity = true;}
if (((NumericValue)value).isNaN()) {
sum = DoubleValue.NaN;
break;
}
}
try {
sum = (ComputableValue) sum.promote(value);
//Aggregate next values
sum = sum.plus((ComputableValue) value);
} catch(final XPathException e) {
throw new XPathException(this, ErrorCodes.FORG0006, e.getMessage());
}
}
result = sum.div(new IntegerValue(inner.getItemCount()));
}
if (!gotInfinity) {
if (Type.subTypeOf(result.getItemType(), Type.NUMBER) &&
((NumericValue)result).isInfinite()) {
//Throw an overflow exception here since we get an infinity