Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,15 @@ protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compIns
}

// assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc)
// For OpGT and OpGE, use DCMPL/FCMPL (NaN yields -1) like javac, so that
// a comparison with NaN is false; DCMPG/FCMPG (NaN yields 1) otherwise.
boolean greaterThan = (compInstruction1 == IFLE || compInstruction1 == IFLT);
if (targetType == 'D') {
mv.visitInsn(DCMPG);
mv.visitInsn(greaterThan ? DCMPL : DCMPG);
mv.visitJumpInsn(compInstruction1, elseTarget);
}
else if (targetType == 'F') {
mv.visitInsn(FCMPG);
mv.visitInsn(greaterThan ? FCMPL : FCMPG);
mv.visitJumpInsn(compInstruction1, elseTarget);
}
else if (targetType == 'J') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,20 @@ void opGe() {
assertThat((Boolean) expression.getValue()).isTrue();
}

@ParameterizedTest
@ValueSource(strings = {
"T(Double).NaN > 1.0d", "1.0d > T(Double).NaN", "T(Double).NaN >= 1.0d", "1.0d >= T(Double).NaN",
"T(Double).NaN < 1.0d", "1.0d < T(Double).NaN", "T(Double).NaN <= 1.0d", "1.0d <= T(Double).NaN",
"T(Float).NaN > 1.0f", "1.0f > T(Float).NaN", "T(Float).NaN >= 1.0f", "1.0f >= T(Float).NaN",
"T(Float).NaN < 1.0f", "1.0f < T(Float).NaN", "T(Float).NaN <= 1.0f", "1.0f <= T(Float).NaN"
})
void relationalOperatorsWithNaN(String expressionString) {
expression = parse(expressionString);
assertThat((Boolean) expression.getValue()).isFalse();
assertCanCompile(expression);
assertThat((Boolean) expression.getValue()).isFalse();
}

@Test
void opEq() {
String tvar = "35";
Expand Down