AtomicComparer comparer,
XPathContext context) throws XPathException {
comparer = comparer.provideContext(context);
BuiltInAtomicType t0 = a0.getPrimitiveType();
BuiltInAtomicType t1 = a1.getPrimitiveType();
// If either operand is a number, convert both operands to xs:double using
// the rules of the number() function, and compare them
if (t0.isPrimitiveNumeric() || t1.isPrimitiveNumeric()) {
DoubleValue v0 = NumberFn.convert(a0);
DoubleValue v1 = NumberFn.convert(a1);
return ValueComparison.compare(v0, operator, v1, comparer);
}
// If either operand is a string, or if both are untyped atomic, convert
// both operands to strings and compare them
if (t0.equals(BuiltInAtomicType.STRING) || t1.equals(BuiltInAtomicType.STRING) ||
(t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC) && t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC))) {
StringValue s0 = (StringValue)a0.convert(BuiltInAtomicType.STRING, true, context).asAtomic();
StringValue s1 = (StringValue)a1.convert(BuiltInAtomicType.STRING, true, context).asAtomic();
return ValueComparison.compare(s0, operator, s1, comparer);
}
// If either operand is untyped atomic,
// convert it to the type of the other operand, and compare
if (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) {
a0 = a0.convert(t1, true, context).asAtomic();
}
if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) {
a1 = a1.convert(t0, true, context).asAtomic();
}
return ValueComparison.compare(a0, operator, a1, comparer);
}