ASF Bugzilla – Attachment 30392 Details for
Bug 55058
[PATCH] patch for missing function FactDouble
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
FactDouble patch
FACTDOUBLE.patch (text/plain), 6.13 KB, created by
Cédric Walter
on 2013-06-04 20:59:08 UTC
(
hide
)
Description:
FactDouble patch
Filename:
MIME Type:
Creator:
Cédric Walter
Created:
2013-06-04 20:59:08 UTC
Size:
6.13 KB
patch
obsolete
>Index: poi/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java (revision ) >+++ poi/src/testcases/org/apache/poi/ss/formula/functions/TestFactDoubleFunctionsFromSpreadsheet.java (revision ) >@@ -0,0 +1,31 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You 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. >+==================================================================== */ >+ >+package org.apache.poi.ss.formula.functions; >+ >+/** >+ * Tests FactDouble() as loaded from a test data spreadsheet.<p/> >+ * >+ * @author cedric dot walter @ gmail dot com >+ */ >+public class TestFactDoubleFunctionsFromSpreadsheet extends BaseTestFunctionsFromSpreadsheet { >+ >+ @Override >+ protected String getFilename() { >+ return "FactDoubleFunctionTestCaseData.xls"; >+ } >+} >\ No newline at end of file >Index: poi/src/java/org/apache/poi/ss/formula/functions/FactDouble.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/java/org/apache/poi/ss/formula/functions/FactDouble.java (revision ) >+++ poi/src/java/org/apache/poi/ss/formula/functions/FactDouble.java (revision ) >@@ -0,0 +1,86 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You 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. >+==================================================================== */ >+ >+package org.apache.poi.ss.formula.functions; >+ >+import org.apache.poi.ss.formula.OperationEvaluationContext; >+import org.apache.poi.ss.formula.eval.*; >+ >+import java.math.BigInteger; >+import java.util.HashMap; >+ >+/** >+ * Implementation for Excel FACTDOUBLE() function.<p/> >+ * <p/> >+ * <b>Syntax</b>:<br/> <b>FACTDOUBLE </b>(<b>number</b>)<br/> >+ * <p/> >+ * Returns the double factorial of a number. >+ * <p/> >+ * Number is the value for which to return the double factorial. If number is not an integer, it is truncated. >+ * <p/> >+ * Remarks >+ * <ul> >+ * <li>If number is nonnumeric, FACTDOUBLE returns the #VALUE! error value.</li> >+ * <li>If number is negative, FACTDOUBLE returns the #NUM! error value.</li> >+ * </ul> >+ * Use a cache for more speed of previously calculated factorial >+ * >+ * @author cedric dot walter @ gmail dot com >+ */ >+public class FactDouble extends Fixed1ArgFunction implements FreeRefFunction { >+ >+ public static final FreeRefFunction instance = new FactDouble(); >+ >+ //Caching of previously calculated factorial for speed >+ static HashMap<Integer, BigInteger> cache = new HashMap<Integer, BigInteger>(); >+ >+ @Override >+ public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) { >+ int number = 0; >+ try { >+ number = OperandResolver.coerceValueToInt(numberVE); >+ } catch (EvaluationException e) { >+ return ErrorEval.VALUE_INVALID; >+ } >+ >+ if (number < 0) { >+ return ErrorEval.NUM_ERROR; >+ } >+ >+ String value = String.valueOf(factorial(number)); >+ return new StringEval(value); >+ } >+ >+ public static BigInteger factorial(int n) { >+ BigInteger result; >+ if (n == 0 || n < 0) { >+ return BigInteger.ONE; >+ } >+ >+ result = BigInteger.valueOf(n).multiply(factorial(n - 2)); >+ cache.put(n, result); >+ return result; >+ } >+ >+ @Override >+ public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { >+ if (args.length != 1) { >+ return ErrorEval.VALUE_INVALID; >+ } >+ return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0]); >+ } >+} >Index: poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (revision 1488867) >+++ poi/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (revision ) >@@ -103,7 +103,7 @@ > r(m, "EOMONTH", null); > r(m, "ERF", null); > r(m, "ERFC", null); >- r(m, "FACTDOUBLE", null); >+ r(m, "FACTDOUBLE", FactDouble.instance); > r(m, "FVSCHEDULE", null); > r(m, "GCD", null); > r(m, "GESTEP", null);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 55058
:
30391
| 30392 |
30455