提交 f50e3ca5 authored 作者: Thomas Mueller's avatar Thomas Mueller

The double or float value -0.0 is now distinct from 0.0 (as in Java).

上级 b02018f9
...@@ -528,21 +528,31 @@ public class Data { ...@@ -528,21 +528,31 @@ public class Data {
break; break;
case Value.DOUBLE: { case Value.DOUBLE: {
double x = v.getDouble(); double x = v.getDouble();
if (x == 0.0 || x == 1.0) { if (x == 1.0f) {
writeByte((byte) (DOUBLE_0_1 + x)); writeByte((byte) (DOUBLE_0_1 + 1));
} else {
long d = Double.doubleToLongBits(x);
if (d == ValueDouble.ZERO_BITS) {
writeByte((byte) DOUBLE_0_1);
} else { } else {
writeByte((byte) type); writeByte((byte) type);
writeVarLong(MathUtils.reverseLong(Double.doubleToLongBits(x))); writeVarLong(MathUtils.reverseLong(d));
}
} }
break; break;
} }
case Value.FLOAT: { case Value.FLOAT: {
float x = v.getFloat(); float x = v.getFloat();
if (x == 0.0f || x == 1.0f) { if (x == 1.0f) {
writeByte((byte) (FLOAT_0_1 + x)); writeByte((byte) (FLOAT_0_1 + 1));
} else {
int f = Float.floatToIntBits(x);
if (f == ValueFloat.ZERO_BITS) {
writeByte((byte) FLOAT_0_1);
} else { } else {
writeByte((byte) type); writeByte((byte) type);
writeVarInt(MathUtils.reverseInt(Float.floatToIntBits(v.getFloat()))); writeVarInt(MathUtils.reverseInt(f));
}
} }
break; break;
} }
......
...@@ -27,10 +27,14 @@ public class ValueDouble extends Value { ...@@ -27,10 +27,14 @@ public class ValueDouble extends Value {
*/ */
public static final int DISPLAY_SIZE = 24; public static final int DISPLAY_SIZE = 24;
/**
* Double.doubleToLongBits(0.0)
*/
public static final long ZERO_BITS = Double.doubleToLongBits(0.0);
private static final ValueDouble ZERO = new ValueDouble(0.0); private static final ValueDouble ZERO = new ValueDouble(0.0);
private static final ValueDouble ONE = new ValueDouble(1.0); private static final ValueDouble ONE = new ValueDouble(1.0);
private static final ValueDouble NAN = new ValueDouble(Double.NaN); private static final ValueDouble NAN = new ValueDouble(Double.NaN);
private static final long ZERO_BITS = Double.doubleToLongBits(0.0);
private final double value; private final double value;
......
...@@ -16,6 +16,11 @@ import org.h2.message.DbException; ...@@ -16,6 +16,11 @@ import org.h2.message.DbException;
*/ */
public class ValueFloat extends Value { public class ValueFloat extends Value {
/**
* Float.floatToIntBits(0.0F).
*/
public static final int ZERO_BITS = Float.floatToIntBits(0.0F);
/** /**
* The precision in digits. * The precision in digits.
*/ */
...@@ -29,7 +34,6 @@ public class ValueFloat extends Value { ...@@ -29,7 +34,6 @@ public class ValueFloat extends Value {
private static final ValueFloat ZERO = new ValueFloat(0.0F); private static final ValueFloat ZERO = new ValueFloat(0.0F);
private static final ValueFloat ONE = new ValueFloat(1.0F); private static final ValueFloat ONE = new ValueFloat(1.0F);
private static final int ZERO_BITS = Float.floatToIntBits(0.0F);
private final float value; private final float value;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论