提交 21d886ed authored 作者: Thomas Mueller's avatar Thomas Mueller

Infinite numbers in SQL script are listed as POWER(0, -1)), negative infinite as…

Infinite numbers in SQL script are listed as POWER(0, -1)), negative infinite as (-POWER(0, -1)), and NaN (not a number) as SQRT(-1).
Comparison did not work correctly when using the special double and float value 'NaN' (not a number).
上级 0cdcc4c4
...@@ -58,6 +58,14 @@ public class ValueDouble extends Value { ...@@ -58,6 +58,14 @@ public class ValueDouble extends Value {
} }
public String getSQL() { public String getSQL() {
if (value == Double.POSITIVE_INFINITY) {
return "POWER(0, -1)";
} else if (value == Double.NEGATIVE_INFINITY) {
return "(-POWER(0, -1))";
} else if (value != value) {
// NaN
return "SQRT(-1)";
}
return getString(); return getString();
} }
...@@ -67,10 +75,7 @@ public class ValueDouble extends Value { ...@@ -67,10 +75,7 @@ public class ValueDouble extends Value {
protected int compareSecure(Value o, CompareMode mode) { protected int compareSecure(Value o, CompareMode mode) {
ValueDouble v = (ValueDouble) o; ValueDouble v = (ValueDouble) o;
if (value == v.value) { return Double.compare(value, v.value);
return 0;
}
return value > v.value ? 1 : -1;
} }
public int getSignum() { public int getSignum() {
...@@ -121,7 +126,10 @@ public class ValueDouble extends Value { ...@@ -121,7 +126,10 @@ public class ValueDouble extends Value {
} }
public boolean equals(Object other) { public boolean equals(Object other) {
return other instanceof ValueDouble && value == ((ValueDouble) other).value; if (!(other instanceof ValueDouble)) {
return false;
}
return compareSecure((ValueDouble) other, null) == 0;
} }
} }
...@@ -58,6 +58,14 @@ public class ValueFloat extends Value { ...@@ -58,6 +58,14 @@ public class ValueFloat extends Value {
} }
public String getSQL() { public String getSQL() {
if (value == Float.POSITIVE_INFINITY) {
return "POWER(0, -1)";
} else if (value == Float.NEGATIVE_INFINITY) {
return "(-POWER(0, -1))";
} else if (value != value) {
// NaN
return "SQRT(-1)";
}
return getString(); return getString();
} }
...@@ -67,10 +75,7 @@ public class ValueFloat extends Value { ...@@ -67,10 +75,7 @@ public class ValueFloat extends Value {
protected int compareSecure(Value o, CompareMode mode) { protected int compareSecure(Value o, CompareMode mode) {
ValueFloat v = (ValueFloat) o; ValueFloat v = (ValueFloat) o;
if (value == v.value) { return Float.compare(value, v.value);
return 0;
}
return value > v.value ? 1 : -1;
} }
public int getSignum() { public int getSignum() {
...@@ -121,7 +126,10 @@ public class ValueFloat extends Value { ...@@ -121,7 +126,10 @@ public class ValueFloat extends Value {
} }
public boolean equals(Object other) { public boolean equals(Object other) {
return other instanceof ValueFloat && value == ((ValueFloat) other).value; if (!(other instanceof ValueFloat)) {
return false;
}
return compareSecure((ValueFloat) other, null) == 0;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论