提交 f6a0794f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use constants from ValueDouble and ValueFloat in more places

上级 2d1d919c
...@@ -589,13 +589,13 @@ public class ValueDataType implements DataType { ...@@ -589,13 +589,13 @@ public class ValueDataType implements DataType {
ordinal < 5 ? 0 : readVarLong(buff)); ordinal < 5 ? 0 : readVarLong(buff));
} }
case FLOAT_0_1: case FLOAT_0_1:
return ValueFloat.get(0); return ValueFloat.ZERO;
case FLOAT_0_1 + 1: case FLOAT_0_1 + 1:
return ValueFloat.get(1); return ValueFloat.ONE;
case DOUBLE_0_1: case DOUBLE_0_1:
return ValueDouble.get(0); return ValueDouble.ZERO;
case DOUBLE_0_1 + 1: case DOUBLE_0_1 + 1:
return ValueDouble.get(1); return ValueDouble.ONE;
case Value.DOUBLE: case Value.DOUBLE:
return ValueDouble.get(Double.longBitsToDouble( return ValueDouble.get(Double.longBitsToDouble(
Long.reverse(readVarLong(buff)))); Long.reverse(readVarLong(buff))));
......
...@@ -809,13 +809,13 @@ public class Data { ...@@ -809,13 +809,13 @@ public class Data {
case Value.STRING_FIXED: case Value.STRING_FIXED:
return ValueStringFixed.get(readString()); return ValueStringFixed.get(readString());
case FLOAT_0_1: case FLOAT_0_1:
return ValueFloat.get(0); return ValueFloat.ZERO;
case FLOAT_0_1 + 1: case FLOAT_0_1 + 1:
return ValueFloat.get(1); return ValueFloat.ONE;
case DOUBLE_0_1: case DOUBLE_0_1:
return ValueDouble.get(0); return ValueDouble.ZERO;
case DOUBLE_0_1 + 1: case DOUBLE_0_1 + 1:
return ValueDouble.get(1); return ValueDouble.ONE;
case Value.DOUBLE: case Value.DOUBLE:
return ValueDouble.get(Double.longBitsToDouble( return ValueDouble.get(Double.longBitsToDouble(
Long.reverse(readVarLong()))); Long.reverse(readVarLong())));
......
...@@ -963,7 +963,7 @@ public abstract class Value { ...@@ -963,7 +963,7 @@ public abstract class Value {
private ValueDouble convertToDouble() { private ValueDouble convertToDouble() {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueDouble.get(getBoolean() ? 1 : 0); return getBoolean() ? ValueDouble.ONE : ValueDouble.ZERO;
case BYTE: case BYTE:
case SHORT: case SHORT:
case INT: case INT:
...@@ -984,7 +984,7 @@ public abstract class Value { ...@@ -984,7 +984,7 @@ public abstract class Value {
private ValueFloat convertToFloat() { private ValueFloat convertToFloat() {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueFloat.get(getBoolean() ? 1 : 0); return getBoolean() ? ValueFloat.ONE : ValueFloat.ZERO;
case BYTE: case BYTE:
case SHORT: case SHORT:
case INT: case INT:
......
...@@ -28,12 +28,20 @@ public class ValueDouble extends Value { ...@@ -28,12 +28,20 @@ public class ValueDouble extends Value {
public static final int DISPLAY_SIZE = 24; public static final int DISPLAY_SIZE = 24;
/** /**
* Double.doubleToLongBits(0.0) * Double.doubleToLongBits(0d)
*/ */
public static final long ZERO_BITS = Double.doubleToLongBits(0.0); public static final long ZERO_BITS = 0L;
/**
* The value 0.
*/
public static final ValueDouble ZERO = new ValueDouble(0d);
/**
* The value 1.
*/
public static final ValueDouble ONE = new ValueDouble(1d);
private static final ValueDouble ZERO = new ValueDouble(0.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 final double value; private final double value;
...@@ -45,24 +53,24 @@ public class ValueDouble extends Value { ...@@ -45,24 +53,24 @@ public class ValueDouble extends Value {
@Override @Override
public Value add(Value v) { public Value add(Value v) {
ValueDouble v2 = (ValueDouble) v; ValueDouble v2 = (ValueDouble) v;
return ValueDouble.get(value + v2.value); return get(value + v2.value);
} }
@Override @Override
public Value subtract(Value v) { public Value subtract(Value v) {
ValueDouble v2 = (ValueDouble) v; ValueDouble v2 = (ValueDouble) v;
return ValueDouble.get(value - v2.value); return get(value - v2.value);
} }
@Override @Override
public Value negate() { public Value negate() {
return ValueDouble.get(-value); return get(-value);
} }
@Override @Override
public Value multiply(Value v) { public Value multiply(Value v) {
ValueDouble v2 = (ValueDouble) v; ValueDouble v2 = (ValueDouble) v;
return ValueDouble.get(value * v2.value); return get(value * v2.value);
} }
@Override @Override
...@@ -71,7 +79,7 @@ public class ValueDouble extends Value { ...@@ -71,7 +79,7 @@ public class ValueDouble extends Value {
if (v2.value == 0.0) { if (v2.value == 0.0) {
throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
} }
return ValueDouble.get(value / v2.value); return get(value / v2.value);
} }
@Override @Override
...@@ -80,7 +88,7 @@ public class ValueDouble extends Value { ...@@ -80,7 +88,7 @@ public class ValueDouble extends Value {
if (other.value == 0) { if (other.value == 0) {
throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
} }
return ValueDouble.get(value % other.value); return get(value % other.value);
} }
@Override @Override
......
...@@ -16,11 +16,6 @@ import org.h2.message.DbException; ...@@ -16,11 +16,6 @@ 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.
*/ */
...@@ -32,8 +27,21 @@ public class ValueFloat extends Value { ...@@ -32,8 +27,21 @@ public class ValueFloat extends Value {
*/ */
static final int DISPLAY_SIZE = 15; static final int DISPLAY_SIZE = 15;
private static final ValueFloat ZERO = new ValueFloat(0.0F); /**
private static final ValueFloat ONE = new ValueFloat(1.0F); * Float.floatToIntBits(0f).
*/
public static final int ZERO_BITS = 0;
/**
* The value 0.
*/
public static final ValueFloat ZERO = new ValueFloat(0f);
/**
* The value 1.
*/
public static final ValueFloat ONE = new ValueFloat(1f);
private static final ValueFloat NAN = new ValueFloat(Float.NaN); private static final ValueFloat NAN = new ValueFloat(Float.NaN);
private final float value; private final float value;
...@@ -45,24 +53,24 @@ public class ValueFloat extends Value { ...@@ -45,24 +53,24 @@ public class ValueFloat extends Value {
@Override @Override
public Value add(Value v) { public Value add(Value v) {
ValueFloat v2 = (ValueFloat) v; ValueFloat v2 = (ValueFloat) v;
return ValueFloat.get(value + v2.value); return get(value + v2.value);
} }
@Override @Override
public Value subtract(Value v) { public Value subtract(Value v) {
ValueFloat v2 = (ValueFloat) v; ValueFloat v2 = (ValueFloat) v;
return ValueFloat.get(value - v2.value); return get(value - v2.value);
} }
@Override @Override
public Value negate() { public Value negate() {
return ValueFloat.get(-value); return get(-value);
} }
@Override @Override
public Value multiply(Value v) { public Value multiply(Value v) {
ValueFloat v2 = (ValueFloat) v; ValueFloat v2 = (ValueFloat) v;
return ValueFloat.get(value * v2.value); return get(value * v2.value);
} }
@Override @Override
...@@ -71,7 +79,7 @@ public class ValueFloat extends Value { ...@@ -71,7 +79,7 @@ public class ValueFloat extends Value {
if (v2.value == 0.0) { if (v2.value == 0.0) {
throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
} }
return ValueFloat.get(value / v2.value); return get(value / v2.value);
} }
@Override @Override
...@@ -80,7 +88,7 @@ public class ValueFloat extends Value { ...@@ -80,7 +88,7 @@ public class ValueFloat extends Value {
if (other.value == 0) { if (other.value == 0) {
throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL()); throw DbException.get(ErrorCode.DIVISION_BY_ZERO_1, getSQL());
} }
return ValueFloat.get(value % other.value); return get(value % other.value);
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论