spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.COSH written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 00:11:56
stats
2 file(s) changed, 32 insertions(+), 2 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index d64e672..1339250 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -97,11 +97,22 @@ var CORREL = Formula["CORREL"];
 6  */
 7 var COS = function (...values) : number {
 8   checkArgumentsLength(values, 1);
 9-  var rad = firstValueAsNumber(values[0]);
10-  return Math.cos(rad);
11+  var r = firstValueAsNumber(values[0]);
12+  return Math.cos(r);
13+};
14+
15+/**
16+ * Returns the hyperbolic cosine of any real number.
17+ * @param values[0] Any real value to calculate the hyperbolic cosine of.
18+ * @returns {number} the hyperbolic cosine of the input
19+ * @constructor
20+ */
21+var COSH = function (...values) : number {
22+  checkArgumentsLength(values, 1);
23+  var r = firstValueAsNumber(values[0]);
24+  return Math["cosh"](r);
25 };
26 
27-var COSH = Formula["COSH"];
28 var COT = Formula["COT"];
29 var COTH = Formula["COTH"];
30 var COUNT = Formula["COUNT"];
31diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
32index 7bac297..7417d2b 100644
33--- a/tests/FormulasTest.ts
34+++ b/tests/FormulasTest.ts
35@@ -369,7 +369,24 @@ catchAndAssertEquals(function() {
36 assertEquals(COS([0, "str"]), 1);
37 
38 
39+// Test COSH
40 assertEquals(COSH(PI()), 11.591953275521522);
41+assertEquals(COSH(1), 1.5430806348152437);
42+assertEquals(COSH(false), 1);
43+assertEquals(COSH(0), 1);
44+assertEquals(COSH(true), 1.5430806348152437);
45+assertEquals(COSH(""), 1);
46+catchAndAssertEquals(function() {
47+  COSH("str");
48+}, ERRORS.VALUE_ERROR);
49+catchAndAssertEquals(function() {
50+  COSH();
51+}, ERRORS.NA_ERROR);
52+catchAndAssertEquals(function() {
53+  COSH(1, 1);
54+}, ERRORS.NA_ERROR);
55+assertEquals(COSH([0, "str"]), 1);
56+
57 
58 assertEquals(COT(30), -0.15611995216165922);
59