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