Skip to content

Commit

Permalink
[bugfix] Fix Math ops on xs:integer from xs:numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 9, 2024
1 parent ecc7875 commit 756462c
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public NumericValue round(final IntegerValue precision) throws XPathException {

@Override
public ComputableValue minus(final ComputableValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER))
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC))
// return new IntegerValue(value - ((IntegerValue) other).value, type);
{
return new IntegerValue(getExpression(), value.subtract(((IntegerValue) other).value), type);
Expand All @@ -388,7 +388,7 @@ public ComputableValue minus(final ComputableValue other) throws XPathException

@Override
public ComputableValue plus(final ComputableValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER))
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC))
// return new IntegerValue(value + ((IntegerValue) other).value, type);
{
return new IntegerValue(getExpression(), value.add(((IntegerValue) other).value), type);
Expand All @@ -399,7 +399,7 @@ public ComputableValue plus(final ComputableValue other) throws XPathException {

@Override
public ComputableValue mult(final ComputableValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER)) {
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC)) {
return new IntegerValue(getExpression(), value.multiply(((IntegerValue) other).value), type);
} else if (Type.subTypeOf(other.getType(), Type.DURATION)) {
return other.mult(this);
Expand Down Expand Up @@ -443,7 +443,7 @@ public IntegerValue idiv(final NumericValue other) throws XPathException {

@Override
public NumericValue mod(final NumericValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER)) {
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC)) {
if (other.isZero()) {
throw new XPathException(getExpression(), ErrorCodes.FOAR0001, "division by zero");
}
Expand All @@ -468,7 +468,7 @@ public NumericValue abs() throws XPathException {

@Override
public AtomicValue max(final Collator collator, final AtomicValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER)) {
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC)) {
return new IntegerValue(getExpression(), value.max(((IntegerValue) other).value));
} else {
return convertTo(other.getType()).max(collator, other);
Expand All @@ -477,7 +477,7 @@ public AtomicValue max(final Collator collator, final AtomicValue other) throws

@Override
public AtomicValue min(final Collator collator, final AtomicValue other) throws XPathException {
if (Type.subTypeOf(other.getType(), Type.INTEGER)) {
if (Type.subTypeOf(other.getType(), Type.INTEGER) || (other instanceof IntegerValue && other.getType() == Type.NUMERIC)) {
return new IntegerValue(getExpression(), value.min(((IntegerValue) other).value));
} else {
return convertTo(other.getType()).min(collator, other);
Expand Down

0 comments on commit 756462c

Please sign in to comment.