You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/09/12 01:48:02 UTC

svn commit: r1383676 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java

Author: prestonc
Date: Tue Sep 11 23:48:01 2012
New Revision: 1383676

URL: http://svn.apache.org/viewvc?rev=1383676&view=rev
Log:
Added check for converting -0 to decimal.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java?rev=1383676&r1=1383675&r2=1383676&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDecimalOperation.java Tue Sep 11 23:48:01 2012
@@ -26,7 +26,7 @@ public class CastToDecimalOperation exte
     private DataOutput dOutInner = abvsInner.getDataOutput();
     private CastToStringOperation castToString = new CastToStringOperation();
     private UTF8StringPointable stringp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
-    
+
     @Override
     public void convertBoolean(BooleanPointable boolp, DataOutput dOut) throws SystemException, IOException {
         long value = (boolp.getBoolean() ? 1 : 0);
@@ -43,6 +43,13 @@ public class CastToDecimalOperation exte
 
     @Override
     public void convertDouble(DoublePointable doublep, DataOutput dOut) throws SystemException, IOException {
+        if (doublep.getDouble() == 0) {
+            long bits = Double.doubleToLongBits(doublep.getDouble());
+            boolean negative = ((bits >> 63) == 0) ? false : true;
+            if (negative) {
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
         abvsInner.reset();
         castToString.convertDoubleCanonical(doublep, dOutInner);
         stringp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1, abvsInner.getLength() - 1);
@@ -51,6 +58,13 @@ public class CastToDecimalOperation exte
 
     @Override
     public void convertFloat(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
+        if (floatp.getFloat() == 0) {
+            long bits = Float.floatToIntBits(floatp.getFloat());
+            boolean negative = ((bits >> 31) == 0) ? false : true;
+            if (negative) {
+                throw new SystemException(ErrorCode.FORG0001);
+            }
+        }
         abvsInner.reset();
         castToString.convertFloatCanonical(floatp, dOutInner);
         stringp.set(abvsInner.getByteArray(), abvsInner.getStartOffset() + 1, abvsInner.getLength() - 1);