commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r570179 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
Date Mon, 27 Aug 2007 16:49:35 GMT
Author: mbenson
Date: Mon Aug 27 09:49:28 2007
New Revision: 570179

URL: http://svn.apache.org/viewvc?rev=570179&view=rev
Log:
[JXPATH-102] Core rounding functions don't handle NaN or infinite values correctly; from Sergey
Vladimirov

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java?rev=570179&r1=570178&r2=570179&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
Mon Aug 27 09:49:28 2007
@@ -653,18 +653,27 @@
     protected Object functionFloor(EvalContext context) {
         assertArgCount(1);
         double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+        	return new Double(v);
+        }
         return new Double(Math.floor(v));
     }
 
     protected Object functionCeiling(EvalContext context) {
         assertArgCount(1);
         double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+        	return new Double(v);
+        }
         return new Double(Math.ceil(v));
     }
 
     protected Object functionRound(EvalContext context) {
         assertArgCount(1);
         double v = InfoSetUtil.doubleValue(getArg1().computeValue(context));
+        if (Double.isNaN(v) || Double.isInfinite(v)) {
+        	return new Double(v);
+        }
         return new Double(Math.round(v));
     }
 

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java?rev=570179&r1=570178&r2=570179&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
(original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/CoreFunctionTest.java
Mon Aug 27 09:49:28 2007
@@ -116,6 +116,16 @@
         assertXPathValue(context, "ceiling(-1.5)", new Double(-1));
         assertXPathValue(context, "round(1.5)", new Double(2));
         assertXPathValue(context, "round(-1.5)", new Double(-1));
+
+        assertXPathValue(context, "floor('NaN')", new Double(Double.NaN));
+        assertXPathValue(context, "floor(-2 div 0)", new Double(Double.NEGATIVE_INFINITY));
+        assertXPathValue(context, "floor(2 div 0)", new Double(Double.POSITIVE_INFINITY));
+        assertXPathValue(context, "ceiling('NaN')", new Double(Double.NaN));
+        assertXPathValue(context, "ceiling(-2 div 0)", new Double(Double.NEGATIVE_INFINITY));
+        assertXPathValue(context, "ceiling(2 div 0)", new Double(Double.POSITIVE_INFINITY));
+        assertXPathValue(context, "round('NaN')", new Double(Double.NaN));
+        assertXPathValue(context, "round(-2 div 0)", new Double(Double.NEGATIVE_INFINITY));
+        assertXPathValue(context, "round(2 div 0)", new Double(Double.POSITIVE_INFINITY));
     }
 
     public void testIDFunction() {



Mime
View raw message