commit
message
[FACTDOUBLE] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-16 01:06:33
stats
8 file(s) changed,
98 insertions(+),
5 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Math.js
src/Formulas/AllFormulas.ts
src/Formulas/Math.ts
tests/Formulas/MathTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 1e04354..e0ac0a2 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -1225,6 +1225,15 @@
6 @returns {number}
7 @constructor
8 ```
9+
10+### ACTDOUBLE
11+
12+```
13+ Calculates the double-factorial of a number.
14+@param value - value or reference to calculate.
15+@returns {number}
16+@constructor
17+```
18 ## Statistical
19
20
21diff --git a/TODO.md b/TODO.md
22index e8ea9a8..b2bbc48 100644
23--- a/TODO.md
24+++ b/TODO.md
25@@ -51,7 +51,6 @@ For example 64 tbs to a qt.
26 * ROWS
27 * VLOOKUP
28 * COUNTBLANK
29-* FACTDOUBLE
30 * MULTINOMIAL
31 * SERIESSUM
32 * SUBTOTAL
33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
34index f3cf143..41b3da6 100644
35--- a/dist/Formulas/AllFormulas.js
36+++ b/dist/Formulas/AllFormulas.js
37@@ -72,6 +72,7 @@ exports.QUOTIENT = Math_1.QUOTIENT;
38 exports.UPLUS = Math_1.UPLUS;
39 exports.UMINUS = Math_1.UMINUS;
40 exports.MROUND = Math_1.MROUND;
41+exports.FACTDOUBLE = Math_1.FACTDOUBLE;
42 var Info_1 = require("./Info");
43 exports.NA = Info_1.NA;
44 exports.ISTEXT = Info_1.ISTEXT;
45diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
46index 5788e20..9fddc50 100644
47--- a/dist/Formulas/Math.js
48+++ b/dist/Formulas/Math.js
49@@ -1302,3 +1302,32 @@ var MROUND = function (value, factor) {
50 return Math.round(v / f) * f;
51 };
52 exports.MROUND = MROUND;
53+/**
54+ * Calculates the double-factorial of a number.
55+ * @param value - value or reference to calculate.
56+ * @returns {number}
57+ * @constructor
58+ */
59+var FACTDOUBLE = function (value) {
60+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "FACTDOUBLE");
61+ var n = Math.floor(TypeConverter_1.TypeConverter.firstValueAsNumber(value));
62+ function factDoublePrivate(n) {
63+ if (n <= 0) {
64+ return 1;
65+ }
66+ else {
67+ return n * factDoublePrivate(n - 2);
68+ }
69+ }
70+ if (n === 0) {
71+ return 0;
72+ }
73+ else if (n < 0) {
74+ throw new Errors_1.NumError("Function FACTDOUBLE parameter 1 value is '" + n
75+ + "'. It should be greater than or equal to 0.");
76+ }
77+ else {
78+ return factDoublePrivate(n);
79+ }
80+};
81+exports.FACTDOUBLE = FACTDOUBLE;
82diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
83index 5ad0f58..8402b80 100644
84--- a/src/Formulas/AllFormulas.ts
85+++ b/src/Formulas/AllFormulas.ts
86@@ -69,7 +69,8 @@ import {
87 QUOTIENT,
88 UPLUS,
89 UMINUS,
90- MROUND
91+ MROUND,
92+ FACTDOUBLE
93 } from "./Math";
94 import {
95 NA,
96@@ -337,5 +338,6 @@ export {
97 ISLOGICAL,
98 ISNUMBER,
99 ISNONTEXT,
100- MROUND
101+ MROUND,
102+ FACTDOUBLE
103 }
104\ No newline at end of file
105diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
106index 9adad14..c00ed74 100644
107--- a/src/Formulas/Math.ts
108+++ b/src/Formulas/Math.ts
109@@ -1314,6 +1314,33 @@ var MROUND = function (value, factor) {
110 return Math.round(v / f) * f;
111 };
112
113+
114+/**
115+ * Calculates the double-factorial of a number.
116+ * @param value - value or reference to calculate.
117+ * @returns {number}
118+ * @constructor
119+ */
120+var FACTDOUBLE = function (value) {
121+ ArgsChecker.checkLength(arguments, 1, "FACTDOUBLE");
122+ var n = Math.floor(TypeConverter.firstValueAsNumber(value));
123+ function factDoublePrivate(n) {
124+ if (n <= 0) {
125+ return 1;
126+ } else {
127+ return n * factDoublePrivate(n - 2);
128+ }
129+ }
130+ if (n === 0) {
131+ return 0;
132+ } else if (n < 0) {
133+ throw new NumError("Function FACTDOUBLE parameter 1 value is '" + n
134+ + "'. It should be greater than or equal to 0.");
135+ } else {
136+ return factDoublePrivate(n);
137+ }
138+};
139+
140 export {
141 ABS,
142 ACOS,
143@@ -1385,5 +1412,6 @@ export {
144 QUOTIENT,
145 UPLUS,
146 UMINUS,
147- MROUND
148+ MROUND,
149+ FACTDOUBLE
150 }
151\ No newline at end of file
152diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
153index 2d3dd5d..ab1a153 100644
154--- a/tests/Formulas/MathTest.ts
155+++ b/tests/Formulas/MathTest.ts
156@@ -69,7 +69,8 @@ import {
157 QUOTIENT,
158 UPLUS,
159 UMINUS,
160- MROUND
161+ MROUND,
162+ FACTDOUBLE
163 } from "../../src/Formulas/Math";
164 import * as ERRORS from "../../src/Errors";
165 import {
166@@ -92,6 +93,23 @@ test("MROUND", function(){
167 }, ERRORS.NA_ERROR);
168 });
169
170+
171+test("FACTDOUBLE", function(){
172+ assertEquals(FACTDOUBLE(7), 105);
173+ assertEquals(FACTDOUBLE(6), 48);
174+ assertEquals(FACTDOUBLE(3), 3);
175+ catchAndAssertEquals(function() {
176+ FACTDOUBLE(-1);
177+ }, ERRORS.NUM_ERROR);
178+ catchAndAssertEquals(function() {
179+ FACTDOUBLE.apply(this, []);
180+ }, ERRORS.NA_ERROR);
181+ catchAndAssertEquals(function() {
182+ FACTDOUBLE.apply(this, [10, 10]);
183+ }, ERRORS.NA_ERROR);
184+});
185+
186+
187 test("GAMMALN", function(){
188 assertEquals(GAMMALN(4.5), 2.453736570842444);
189 assertEquals(GAMMALN(3), 0.6931471805599443);
190diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
191index b7422de..fa889a5 100644
192--- a/tests/SheetFormulaTest.ts
193+++ b/tests/SheetFormulaTest.ts
194@@ -675,6 +675,10 @@ test("Sheet MROUND", function(){
195 assertFormulaEquals('=MROUND(21, 14)', 28);
196 });
197
198+test("Sheet FACTDOUBLE", function(){
199+ assertFormulaEquals('=FACTDOUBLE(7)', 105);
200+});
201+
202 test("Sheet *", function(){
203 assertFormulaEquals('= 10 * 10', 100);
204 assertFormulaEquals('= 10 * 0', 0);