Skip to content

Commit 05ff3d1

Browse files
committed
FunRound fixes/improvements
FunRound should use subclass eval method in FunRoundBase. Tests for -ve 0 (not working yet)
1 parent 3900e6f commit 05ff3d1

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunRound.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,4 @@ public int returnsType() {
9494
return RoundingMode.HALF_UP;
9595
}
9696
}
97-
98-
@Override
99-
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
100-
101-
if (args[0].isEmpty()) {
102-
return Sequence.EMPTY_SEQUENCE;
103-
}
104-
105-
final Item item = args[0].itemAt(0);
106-
final NumericValue value;
107-
if (item instanceof NumericValue) {
108-
value = (NumericValue) item;
109-
} else {
110-
value = (NumericValue) item.convertTo(Type.NUMBER);
111-
}
112-
113-
final RoundingMode roundingMode;
114-
if (value.isNegative()) {
115-
roundingMode = RoundingMode.HALF_DOWN;
116-
} else {
117-
roundingMode = RoundingMode.HALF_UP;
118-
}
119-
120-
if (args.length > 1) {
121-
final Item precisionItem = args[1].itemAt(0);
122-
if (precisionItem instanceof IntegerValue) {
123-
final IntegerValue precision = (IntegerValue) precisionItem;
124-
return value.round(precision, roundingMode);
125-
}
126-
}
127-
128-
return value.round(IntegerValue.ZERO, roundingMode);
129-
}
13097
}

exist-core/src/main/java/org/exist/xquery/functions/fn/FunRoundBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
6363
}
6464

6565
final RoundingMode roundingMode = getFunctionRoundingMode(value);
66-
66+
6767
if (args.length > 1) {
6868
final Item precisionItem = args[1].itemAt(0);
6969
if (precisionItem instanceof IntegerValue) {

exist-core/src/test/xquery/numbers/fn-round.xqm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,23 @@ declare
112112
%test:assertEquals(2.0)
113113
function fr:round-half-to-even($number as xs:double) {
114114
fn:round-half-to-even($number)
115+
};
116+
117+
declare
118+
%test:args("-0.41",1)
119+
%test:assertEquals("-0.4")
120+
%test:args("-0.41",0)
121+
%test:assertEquals("-0")
122+
function fr:round-negative-zero($number as xs:decimal, $precision as xs:integer) {
123+
fn:round($number, $precision)
124+
};
125+
126+
127+
declare
128+
%test:args("-0.41",1)
129+
%test:assertEquals("-0.4")
130+
%test:args("-0.41",0)
131+
%test:assertEquals("-0")
132+
function fr:round-negative-zero-double($number as xs:double, $precision as xs:integer) {
133+
fn:round($number, $precision)
115134
};

0 commit comments

Comments
 (0)