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/08/22 01:35:15 UTC

svn commit: r1375854 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/DivideOperation.java

Author: prestonc
Date: Tue Aug 21 23:35:15 2012
New Revision: 1375854

URL: http://svn.apache.org/viewvc?rev=1375854&view=rev
Log:
The decimal divide function threw an unnecessary error and did not return decimal values for integer divide.

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

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/DivideOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/DivideOperation.java?rev=1375854&r1=1375853&r2=1375854&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/DivideOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/arithmetic/DivideOperation.java Tue Aug 21 23:35:15 2012
@@ -62,23 +62,20 @@ public class DivideOperation extends Abs
     public void operateDecimalDecimal(XSDecimalPointable decp1, XSDecimalPointable decp2, DataOutput dOut)
             throws SystemException, IOException {
         // Prepare
-        long value1 = decp1.getDecimalValue();
-        long value2 = decp2.getDecimalValue();
-        byte place1 = decp1.getDecimalPlace();
-        byte place2 = decp2.getDecimalPlace();
+        double value1 = decp1.doubleValue();
+        double value2 = decp2.doubleValue();
         if (value2 == 0) {
             throw new SystemException(ErrorCode.FOAR0001);
         }
         // Divide
-        if (value1 > Long.MAX_VALUE * value2) {
-            throw new SystemException(ErrorCode.XPDY0002);
-        }
         value1 /= value2;
-        place1 -= place2;
         // Save
-        dOut.write(ValueTag.XS_DECIMAL_TAG);
-        dOut.writeByte(place1);
-        dOut.writeLong(value1);
+        abvsInner.reset();
+        DoublePointable doublep = new DoublePointable();
+        doublep.set(abvsInner.getByteArray(), abvsInner.getStartOffset(), DoublePointable.TYPE_TRAITS.getFixedLength());
+        doublep.setDouble(value1);
+        CastToDecimalOperation castToDecmial = new CastToDecimalOperation();
+        castToDecmial.convertDouble(doublep, dOut);
     }
 
     @Override
@@ -463,9 +460,6 @@ public class DivideOperation extends Abs
             throw new SystemException(ErrorCode.FOAR0001);
         }
         // Divide
-        if (value1 > Long.MAX_VALUE * value2) {
-            throw new SystemException(ErrorCode.XPDY0002);
-        }
         value1 /= value2;
         place1 -= place2;
         // Save
@@ -487,9 +481,6 @@ public class DivideOperation extends Abs
             throw new SystemException(ErrorCode.FOAR0001);
         }
         // Divide
-        if (value1 > Long.MAX_VALUE * value2) {
-            throw new SystemException(ErrorCode.XPDY0002);
-        }
         value1 /= value2;
         place1 -= place2;
         // Save