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

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

上级 c90da788
......@@ -479,7 +479,7 @@ condition [ { AND condition } [...] ]
","
Value or condition."
"Other Grammar","Array","
( expression [,...] )
( [ expression, [ expression [,...] ] ] )
","
An array of values."
"Other Grammar","Boolean","
......@@ -576,7 +576,7 @@ A string starts and ends with two dollar signs."
"Other Grammar","Double","
[ + | - ] { { number [ . number ] } | { . number } } [ E [ + | - ] expNumber [...] ] ]
","
The limitations are the same as for the Java data type Double."
A floating point number with high precision."
"Other Grammar","Expression","
andCondition [ { OR andCondition } [...] ]
","
......@@ -716,23 +716,23 @@ Data type with fixed precision and scale."
"Data Types","DOUBLE Type","
{ DOUBLE [ PRECISION ] | FLOAT | FLOAT4 | FLOAT8 }
","
Floating point number."
A floating point number."
"Data Types","REAL Type","
REAL
","
Single precision floating point number."
A single precision floating point number."
"Data Types","TIME Type","
TIME
","
The format is hh:mm:ss."
The time data type."
"Data Types","DATE Type","
DATE
","
The format is yyyy-MM-dd."
The date data type."
"Data Types","TIMESTAMP Type","
{ TIMESTAMP | DATETIME | SMALLDATETIME }
","
The format is yyyy-MM-dd hh:mm:ss[."
The timestamp data type."
"Data Types","BINARY Type","
{ BINARY | VARBINARY | LONGVARBINARY | RAW | BYTEA } [ ( precisionInt ) ]
","
......
......@@ -27,11 +27,10 @@ public class ValueDouble extends Value {
*/
public static final int DISPLAY_SIZE = 24;
private static final double DOUBLE_ZERO = 0.0;
private static final double DOUBLE_ONE = 1.0;
private static final ValueDouble ZERO = new ValueDouble(DOUBLE_ZERO);
private static final ValueDouble ONE = new ValueDouble(DOUBLE_ONE);
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 long ZERO_BITS = Double.doubleToLongBits(0.0);
private final double value;
......@@ -126,10 +125,14 @@ public class ValueDouble extends Value {
* @return the value
*/
public static ValueDouble get(double d) {
if (DOUBLE_ZERO == d) {
return ZERO;
} else if (DOUBLE_ONE == d) {
if (d == 1.0) {
return ONE;
} else if (d == 0.0) {
// unfortunately, -0.0 == 0.0, but we don't want to return
// 0.0 in this case
if (Double.doubleToLongBits(d) == ZERO_BITS) {
return ZERO;
}
} else if (Double.isNaN(d)) {
return NAN;
}
......
......@@ -27,10 +27,9 @@ public class ValueFloat extends Value {
*/
static final int DISPLAY_SIZE = 15;
private static final float FLOAT_ZERO = 0.0F;
private static final float FLOAT_ONE = 1.0F;
private static final ValueFloat ZERO = new ValueFloat(FLOAT_ZERO);
private static final ValueFloat ONE = new ValueFloat(FLOAT_ONE);
private static final ValueFloat ZERO = new ValueFloat(0.0F);
private static final ValueFloat ONE = new ValueFloat(1.0F);
private static final int ZERO_BITS = Float.floatToIntBits(0.0F);
private final float value;
......@@ -126,10 +125,14 @@ public class ValueFloat extends Value {
* @return the value
*/
public static ValueFloat get(float d) {
if (FLOAT_ZERO == d) {
return ZERO;
} else if (FLOAT_ONE == d) {
if (d == 1.0F) {
return ONE;
} else if (d == 0.0F) {
// unfortunately, -0.0 == 0.0, but we don't want to return
// 0.0 in this case
if (Float.floatToIntBits(d) == ZERO_BITS) {
return ZERO;
}
}
return (ValueFloat) Value.cache(new ValueFloat(d));
}
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
select -cast(0 as double) nz;
> NZ
> -----
> -0.0
> rows: 1
select () empty;
> EMPTY
> -----
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论