瀏覽代碼

HPCC-8922 Fix problems casting constant decimals to booleans

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 12 年之前
父節點
當前提交
5b46631d8c
共有 2 個文件被更改,包括 49 次插入2 次删除
  1. 2 2
      common/deftype/defvalue.cpp
  2. 47 0
      ecl/regress/decimalboolcast.ecl

+ 2 - 2
common/deftype/defvalue.cpp

@@ -2083,7 +2083,7 @@ IValue *DecimalValue::castTo(ITypeInfo *t)
     case type_packedint:
         return createTruncIntValue(DecPopInt64(), LINK(t));
     case type_boolean:
-        return createBoolValue(!DecCompareNull());
+        return createBoolValue(DecCompareNull() != 0);
     case type_decimal:
         return createDecimalValueFromStack(t);
     }
@@ -2138,7 +2138,7 @@ bool DecimalValue::getBoolValue()
 {
     BcdCriticalBlock bcdBlock;
     pushDecimalValue();
-    return DecCompareNull() ? 0 : 1;
+    return DecCompareNull() != 0;
 }
 
 __int64 DecimalValue::getIntValue()

+ 47 - 0
ecl/regress/decimalboolcast.ecl

@@ -0,0 +1,47 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+#IF (1.1D)
+OUTPUT('success');
+#else
+OUTPUT('failure');
+#END
+
+#IF (0.0D)
+OUTPUT('failure');
+#else
+OUTPUT('success');
+#END
+
+#IF ((boolean)1.1D)
+OUTPUT('success');
+#else
+OUTPUT('failure');
+#END
+
+#IF ((boolean)0.0D)
+OUTPUT('failure');
+#else
+OUTPUT('success');
+#END
+
+decimal10_2 zero := 0.0D : stored('zero');
+decimal10_2 one := 1.0D : stored('one');
+
+output((boolean)zero);
+output((boolean)one);
+