Item firstItem = argItor.next();
if(firstItem instanceof UntypedAtomicValue) {
firstItem = ((UntypedAtomicValue) firstItem).castAs(DoubleType.DOUBLE, dynEnv);
}
if(firstItem instanceof XNumber) {
XNumber num = (XNumber) firstItem;
final int scale;
final int args = argv.size();
if(args > 1) {
Item precision = argv.getItem(1);
if(!(precision instanceof XInteger)) {
throw new DynamicError("err:FORG0006", "second argument type for precision is invalid: "
+ precision.getType());
}
scale = ((XInteger) precision).getNumber().intValue();
} else {
scale = 0;
}
XNumber promoted = promote(num, scale);
return promoted;
} else {
throw new DynamicError("err:FORG0006", "Invalid argument type: " + firstItem.getType());
}
}