spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.COTH written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 03:16:10
stats
3 file(s) changed, 42 insertions(+), 1 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
tests/SheetFormulaTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index a806421..4647bb5 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -129,7 +129,22 @@ var COT = function (...values) : number {
 6 };
 7 
 8 
 9-var COTH = Formula["COTH"];
10+/**
11+ * Return the hyperbolic cotangent of a value, defined as coth(x) = 1 / tanh(x).
12+ * @param values[0] value to calculate the hyperbolic cotangent value of
13+ * @returns {number} hyperbolic cotangent
14+ * @constructor
15+ */
16+var COTH = 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 COTH caused a divide by zero error.");
21+  }
22+  return 1 / Math["tanh"](x);
23+};
24+
25+
26 var COUNT = Formula["COUNT"];
27 var COUNTA = Formula["COUNTA"];
28 var COUNTIF = Formula["COUNTIF"];
29diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
30index 43579c6..7858926 100644
31--- a/tests/FormulasTest.ts
32+++ b/tests/FormulasTest.ts
33@@ -413,7 +413,32 @@ catchAndAssertEquals(function() {
34 }, ERRORS.NA_ERROR);
35 
36 
37-assertEquals(COTH(2), 1.0373147207275482);
38+// Test COTH
39+assertEquals(COTH(30), 1);
40+assertEquals(COTH(1), 1.3130352854993315);
41+assertEquals(COTH(true), 1.3130352854993315);
42+assertEquals(COTH([1, "str"]), 1.3130352854993315);
43+assertEquals(COTH(-1), -1.3130352854993315);
44+catchAndAssertEquals(function() {
45+  COTH(false);
46+}, ERRORS.DIV_ZERO_ERROR);
47+catchAndAssertEquals(function() {
48+  COTH(0);
49+}, ERRORS.DIV_ZERO_ERROR);
50+catchAndAssertEquals(function() {
51+  COTH("");
52+}, ERRORS.DIV_ZERO_ERROR);
53+catchAndAssertEquals(function() {
54+  COTH("str");
55+}, ERRORS.VALUE_ERROR);
56+catchAndAssertEquals(function() {
57+  COTH();
58+}, ERRORS.NA_ERROR);
59+catchAndAssertEquals(function() {
60+  COTH(1, 1);
61+}, ERRORS.NA_ERROR);
62+
63+
64 
65 assertEquals(COUNT([1, 5, 10]), 3);
66 
67diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
68index fec6ebb..2bc8e13 100644
69--- a/tests/SheetFormulaTest.ts
70+++ b/tests/SheetFormulaTest.ts
71@@ -198,7 +198,7 @@ testFormula("=COSH(PI())", 11.591953275521522);
72 testFormula('=COT(30)', -0.15611995216165922);
73 
74 // Test COTH
75-testFormula('=COTH(2)', 1.0373147207275482);
76+testFormula('=COTH(2)', 1.037314720727548);
77 
78 // Test COUNT
79 testFormula('=COUNT([1, 5, 10])', 3);