use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method eq.
/**
* Equality comparison between this number and the supplied representation.
* @param aa
* Representation to be compared with (must currently be of type
* XSDouble)
*
* @return True if the 2 representations represent the same number. False
* otherwise
* @since 1.1
*/
public boolean eq(AnyType aa, DynamicContext dynamicContext) throws DynamicError {
ResultSequence rs = ResultSequenceFactory.create_new(aa);
ResultSequence crs = constructor(rs);
if (crs.empty()) {
throw DynamicError.throw_type_error();
}
Item cat = crs.first();
XSDouble d = (XSDouble) cat;
if (d.nan() && nan()) {
return false;
}
Double thatvalue = new Double(d.double_value());
Double thisvalue = new Double(double_value());
return thisvalue.equals(thatvalue);
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method constructor.
/**
* Creates a new result sequence consisting of the retrievable double number
* in the supplied result sequence
*
* @param arg
* The result sequence from which to extract the double number.
* @throws DynamicError
* @return A new result sequence consisting of the double number supplied.
*/
public ResultSequence constructor(ResultSequence arg) throws DynamicError {
if (arg.empty())
return ResultBuffer.EMPTY;
Item aat = arg.first();
if (aat instanceof XSDuration || aat instanceof CalendarType || aat instanceof XSBase64Binary || aat instanceof XSHexBinary || aat instanceof XSAnyURI) {
throw DynamicError.invalidType();
}
if (!isCastable(aat)) {
throw DynamicError.cant_cast(null);
}
XSDouble d = castDouble(aat);
if (d == null)
throw DynamicError.cant_cast(null);
return d;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method lt.
/**
* Comparison between this number and the supplied representation. Currently
* no numeric type promotion exists so the supplied representation must be
* of type XSDouble.
*
* @param arg
* Representation to be compared with (must currently be of type
* XSDouble)
* @return True if the supplied type represents a number greater than this
* one stored. False otherwise
*/
public boolean lt(AnyType arg, DynamicContext context) throws DynamicError {
Item carg = convertArg(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return double_value() < val.double_value();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDouble method minus.
/**
* Mathematical subtraction operator between this XSDouble and the supplied
* ResultSequence.
*
* @param arg
* The ResultSequence to perform an subtraction with
* @return A XSDouble consisting of the result of the mathematical
* subtraction.
*/
public ResultSequence minus(ResultSequence arg) throws DynamicError {
ResultSequence carg = convertResultSequence(arg);
XSDouble val = (XSDouble) get_single_type(carg, XSDouble.class);
return ResultSequenceFactory.create_new(new XSDouble(double_value() - val.double_value()));
}
use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble in project webtools.sourceediting by eclipse.
the class XSDayTimeDuration method div.
/**
* Mathematical division between this duration stored and the supplied
* duration of time (of type XSDayTimeDuration)
*
* @param arg
* The duration of time to divide by
* @return New XSDayTimeDuration representing the resulting duration after
* the division
* @throws DynamicError
*/
public ResultSequence div(ResultSequence arg) throws DynamicError {
if (arg.size() != 1)
DynamicError.throw_type_error();
Item at = arg.first();
if (at instanceof XSDouble) {
XSDouble dt = (XSDouble) at;
double retval = 0;
if (dt.nan()) {
throw DynamicError.nan();
}
if (!dt.zero()) {
BigDecimal ret = new BigDecimal(0);
if (dt.infinite()) {
retval = value() / dt.double_value();
} else {
ret = new BigDecimal(value());
ret = ret.divide(new BigDecimal(dt.double_value()), 18, BigDecimal.ROUND_HALF_EVEN);
retval = ret.doubleValue();
}
} else {
throw DynamicError.overflowUnderflow();
}
return ResultSequenceFactory.create_new(new XSDayTimeDuration(retval));
} else if (at instanceof XSDecimal) {
XSDecimal dt = (XSDecimal) at;
BigDecimal ret = new BigDecimal(0);
if (!dt.zero()) {
ret = new BigDecimal(value());
ret = ret.divide(dt.getValue(), 18, BigDecimal.ROUND_HALF_EVEN);
} else {
throw DynamicError.overflowUnderflow();
}
return ResultSequenceFactory.create_new(new XSDayTimeDuration(ret.intValue()));
} else if (at instanceof XSDayTimeDuration) {
XSDuration md = (XSDuration) at;
BigDecimal res = null;
res = new BigDecimal(this.value());
BigDecimal l = new BigDecimal(md.value());
res = res.divide(l, 18, BigDecimal.ROUND_HALF_EVEN);
return ResultSequenceFactory.create_new(new XSDecimal(res));
} else {
DynamicError.throw_type_error();
// unreach
return null;
}
}
Aggregations