spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.COT written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 03:09:39
stats
2 file(s) changed, 39 insertions(+), 0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 1339250..a806421 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -113,7 +113,22 @@ var COSH = function (...values) : number {
 6   return Math["cosh"](r);
 7 };
 8 
 9-var COT = Formula["COT"];
10+/**
11+ * Returns the cotangent of any real number. Defined as cot(x) = 1 / tan(x).
12+ * @param values[0] number to calculate the cotangent for
13+ * @returns {number} cotangent
14+ * @constructor
15+ */
16+var COT = function (...values) : number {
17+  checkArgumentsLength(values, 1);
18+  var x = firstValueAsNumber(values[0]);
19+  if (x === 0) {
20+    throw new CellError(ERRORS.DIV_ZERO_ERROR, "Evaluation of function COT caused a divide by zero error.");
21+  }
22+  return 1 / Math.tan(x);
23+};
24+
25+
26 var COTH = Formula["COTH"];
27 var COUNT = Formula["COUNT"];
28 var COUNTA = Formula["COUNTA"];
29diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
30index 7417d2b..43579c6 100644
31--- a/tests/FormulasTest.ts
32+++ b/tests/FormulasTest.ts
33@@ -388,7 +388,30 @@ catchAndAssertEquals(function() {
34 assertEquals(COSH([0, "str"]), 1);
35 
36 
37+// Test COT
38 assertEquals(COT(30), -0.15611995216165922);
39+assertEquals(COT(1), 0.6420926159343306);
40+assertEquals(COT(true), 0.6420926159343306);
41+assertEquals(COT([1, "str"]), 0.6420926159343306);
42+catchAndAssertEquals(function() {
43+  COT(false);
44+}, ERRORS.DIV_ZERO_ERROR);
45+catchAndAssertEquals(function() {
46+  COT(0);
47+}, ERRORS.DIV_ZERO_ERROR);
48+catchAndAssertEquals(function() {
49+  COT("");
50+}, ERRORS.DIV_ZERO_ERROR);
51+catchAndAssertEquals(function() {
52+  COT("str");
53+}, ERRORS.VALUE_ERROR);
54+catchAndAssertEquals(function() {
55+  COT();
56+}, ERRORS.NA_ERROR);
57+catchAndAssertEquals(function() {
58+  COT(1, 1);
59+}, ERRORS.NA_ERROR);
60+
61 
62 assertEquals(COTH(2), 1.0373147207275482);
63