提交 5248b286 authored 作者: Thomas Mueller's avatar Thomas Mueller

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

上级 f50e3ca5
...@@ -528,7 +528,7 @@ public class Data { ...@@ -528,7 +528,7 @@ public class Data {
break; break;
case Value.DOUBLE: { case Value.DOUBLE: {
double x = v.getDouble(); double x = v.getDouble();
if (x == 1.0f) { if (x == 1.0d) {
writeByte((byte) (DOUBLE_0_1 + 1)); writeByte((byte) (DOUBLE_0_1 + 1));
} else { } else {
long d = Double.doubleToLongBits(x); long d = Double.doubleToLongBits(x);
...@@ -810,17 +810,25 @@ public class Data { ...@@ -810,17 +810,25 @@ public class Data {
} }
case Value.DOUBLE: { case Value.DOUBLE: {
double x = v.getDouble(); double x = v.getDouble();
if (x == 0.0 || x == 1.0) { if (x == 1.0d) {
return 1;
}
long d = Double.doubleToLongBits(x);
if (d == ValueDouble.ZERO_BITS) {
return 1; return 1;
} }
return 1 + getVarLongLen(MathUtils.reverseLong(Double.doubleToLongBits(x))); return 1 + getVarLongLen(MathUtils.reverseLong(d));
} }
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) {
return 1;
}
int f = Float.floatToIntBits(x);
if (f == ValueFloat.ZERO_BITS) {
return 1; return 1;
} }
return 1 + getVarIntLen(MathUtils.reverseInt(Float.floatToIntBits(v.getFloat()))); return 1 + getVarIntLen(MathUtils.reverseInt(f));
} }
case Value.STRING: { case Value.STRING: {
String s = v.getString(); String s = v.getString();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论