commit
message
[QUOTIENT] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-13 01:22:20
stats
10 file(s) changed,
80 insertions(+),
11 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Math.js
dist/Formulas/Statistical.js
src/Formulas/AllFormulas.ts
src/Formulas/Math.ts
src/Formulas/Statistical.ts
tests/Formulas/MathTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index da1efd1..84099fe 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -1151,6 +1151,16 @@
6 @param values - values or range of values to multiply by each other.
7 @constructor
8 ```
9+
10+### QUOTIENT
11+
12+```
13+ Divide one number by another
14+@param dividend - number to be divided by the divisor.
15+@param divisor - number to divide the dividend.
16+@returns {number}
17+@constructor
18+```
19 ## Statistical
20
21
22@@ -1351,7 +1361,8 @@
23 ```
24 Returns a value nearest to a specified quartile of a set of data.
25 @param data - The array or range containing the set of data to consider.
26-@param quartile - Which quartile value to return. 0 returns 0
27+@param quartile - Which quartile value to return. 0 returns 0 percent mark, 1 returns 25 percent mark, 2 returns 50 percent mark, 3 returns 75 percent mark, 4 returns 100 percent mark.
28+@constructor
29 ```
30 ## Text
31
32diff --git a/TODO.md b/TODO.md
33index b185020..76be2b4 100644
34--- a/TODO.md
35+++ b/TODO.md
36@@ -58,7 +58,6 @@ For example 64 tbs to a qt.
37 * FACTDOUBLE
38 * MROUND
39 * MULTINOMIAL
40-* QUOTIENT
41 * SERIESSUM
42 * SUBTOTAL
43 * UMINUS
44diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
45index 3415886..b04d472 100644
46--- a/dist/Formulas/AllFormulas.js
47+++ b/dist/Formulas/AllFormulas.js
48@@ -68,6 +68,7 @@ exports.GCD = Math_1.GCD;
49 exports.LCM = Math_1.LCM;
50 exports.GAMMALN = Math_1.GAMMALN;
51 exports.PRODUCT = Math_1.PRODUCT;
52+exports.QUOTIENT = Math_1.QUOTIENT;
53 var Info_1 = require("./Info");
54 exports.NA = Info_1.NA;
55 var Lookup_1 = require("./Lookup");
56diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
57index 20e8aa9..28b78b2 100644
58--- a/dist/Formulas/Math.js
59+++ b/dist/Formulas/Math.js
60@@ -1242,3 +1242,20 @@ var PRODUCT = function () {
61 return value;
62 };
63 exports.PRODUCT = PRODUCT;
64+/**
65+ * Divide one number by another
66+ * @param dividend - number to be divided by the divisor.
67+ * @param divisor - number to divide the dividend.
68+ * @returns {number}
69+ * @constructor
70+ */
71+var QUOTIENT = function (dividend, divisor) {
72+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "QUOTIENT");
73+ var dv = TypeConverter_1.TypeConverter.firstValueAsNumber(dividend);
74+ var ds = TypeConverter_1.TypeConverter.firstValueAsNumber(divisor);
75+ if (ds === 0) {
76+ throw new Errors_1.DivZeroError("Function QUOTIENT parameter 2 cannot be zero.");
77+ }
78+ return dv / ds;
79+};
80+exports.QUOTIENT = QUOTIENT;
81diff --git a/dist/Formulas/Statistical.js b/dist/Formulas/Statistical.js
82index 5d6b304..7cafe7c 100644
83--- a/dist/Formulas/Statistical.js
84+++ b/dist/Formulas/Statistical.js
85@@ -554,8 +554,8 @@ exports.PERCENTILE = PERCENTILE;
86 /**
87 * Returns a value nearest to a specified quartile of a set of data.
88 * @param data - The array or range containing the set of data to consider.
89- * @param quartile - Which quartile value to return. 0 returns 0% mark, 1 returns 25% mark, 2 returns 50% mark, 3
90- * returns 75% mark, 4 returns 100% mark.
91+ * @param quartile - Which quartile value to return. 0 returns 0 percent mark, 1 returns 25 percent mark, 2 returns 50
92+ * percent mark, 3 returns 75 percent mark, 4 returns 100 percent mark.
93 * @constructor
94 */
95 var QUARTILE = function (data, quartile) {
96diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
97index 1c3f5d5..13337c9 100644
98--- a/src/Formulas/AllFormulas.ts
99+++ b/src/Formulas/AllFormulas.ts
100@@ -65,7 +65,8 @@ import {
101 GCD,
102 LCM,
103 GAMMALN,
104- PRODUCT
105+ PRODUCT,
106+ QUOTIENT
107 } from "./Math";
108 import {
109 NA
110@@ -313,5 +314,6 @@ export {
111 GAMMALN,
112 QUARTILE,
113 PERCENTILE,
114- PRODUCT
115+ PRODUCT,
116+ QUOTIENT
117 }
118\ No newline at end of file
119diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
120index 05468df..0afcf5e 100644
121--- a/src/Formulas/Math.ts
122+++ b/src/Formulas/Math.ts
123@@ -1250,6 +1250,25 @@ var PRODUCT = function (...values) {
124 return value;
125 };
126
127+
128+/**
129+ * Divide one number by another
130+ * @param dividend - number to be divided by the divisor.
131+ * @param divisor - number to divide the dividend.
132+ * @returns {number}
133+ * @constructor
134+ */
135+var QUOTIENT = function (dividend, divisor) {
136+ ArgsChecker.checkLength(arguments, 2, "QUOTIENT");
137+ var dv = TypeConverter.firstValueAsNumber(dividend);
138+ var ds = TypeConverter.firstValueAsNumber(divisor);
139+ if (ds === 0) {
140+ throw new DivZeroError("Function QUOTIENT parameter 2 cannot be zero.");
141+ }
142+ return dv / ds;
143+};
144+
145+
146 export {
147 ABS,
148 ACOS,
149@@ -1317,5 +1336,6 @@ export {
150 GCD,
151 LCM,
152 GAMMALN,
153- PRODUCT
154+ PRODUCT,
155+ QUOTIENT
156 }
157\ No newline at end of file
158diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
159index d11d52b..5d6fcf0 100644
160--- a/src/Formulas/Statistical.ts
161+++ b/src/Formulas/Statistical.ts
162@@ -537,8 +537,8 @@ var PERCENTILE = function (data, percent) {
163 /**
164 * Returns a value nearest to a specified quartile of a set of data.
165 * @param data - The array or range containing the set of data to consider.
166- * @param quartile - Which quartile value to return. 0 returns 0% mark, 1 returns 25% mark, 2 returns 50% mark, 3
167- * returns 75% mark, 4 returns 100% mark.
168+ * @param quartile - Which quartile value to return. 0 returns 0 percent mark, 1 returns 25 percent mark, 2 returns 50
169+ * percent mark, 3 returns 75 percent mark, 4 returns 100 percent mark.
170 * @constructor
171 */
172 var QUARTILE = function (data, quartile) {
173diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
174index e982e64..2526005 100644
175--- a/tests/Formulas/MathTest.ts
176+++ b/tests/Formulas/MathTest.ts
177@@ -65,7 +65,8 @@ import {
178 GCD,
179 LCM,
180 GAMMALN,
181- PRODUCT
182+ PRODUCT,
183+ QUOTIENT
184 } from "../../src/Formulas/Math";
185 import * as ERRORS from "../../src/Errors";
186 import {
187@@ -119,6 +120,21 @@ test("PRODUCT", function(){
188 });
189
190
191+test("QUOTIENT", function(){
192+ assertEquals(QUOTIENT(2, 2), 1);
193+ assertEquals(QUOTIENT(4, 2), 2);
194+ catchAndAssertEquals(function() {
195+ QUOTIENT(1, 0);
196+ }, ERRORS.DIV_ZERO_ERROR);
197+ catchAndAssertEquals(function() {
198+ QUOTIENT.apply(this, [1]);
199+ }, ERRORS.NA_ERROR);
200+ catchAndAssertEquals(function() {
201+ QUOTIENT.apply(this, [1, 2, 3]);
202+ }, ERRORS.NA_ERROR);
203+});
204+
205+
206 test("GCD", function(){
207 assertEquals(GCD(10, 100), 10);
208 assertEquals(GCD(22, 44), 22);
209diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
210index c304431..0baf63c 100644
211--- a/tests/SheetFormulaTest.ts
212+++ b/tests/SheetFormulaTest.ts
213@@ -263,6 +263,10 @@ test("Sheet PRODUCT", function(){
214 assertFormulaEquals('=PRODUCT(2, 2)', 4);
215 });
216
217+test("Sheet QUOTIENT", function(){
218+ assertFormulaEquals('=QUOTIENT(8, 2)', 4);
219+});
220+
221 test("Sheet PERCENTILE", function(){
222 assertFormulaEquals('=PERCENTILE([10], 0)', 10);
223 });