spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.TANH written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-04 18:11:31
stats
3 file(s) changed, 36 insertions(+), 3 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 44876b9..972fda4 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -148,13 +148,25 @@ var SUMX2PY2 = Formula["SUMX2PY2"];
 6  * @returns {number} tangent in radians
 7  * @constructor
 8  */
 9-var TAN = function (...values) {
10+var TAN = function (...values) : number {
11   checkArgumentsLength(values, 1);
12   var rad = firstValueAsNumber(values[0]);
13   return rad === Math.PI ? 0 : Math.tan(rad);
14 };
15 
16-var TANH = Formula["TANH"];
17+/**
18+ * Returns the hyperbolic tangent of any real number.
19+ * @param values[0] Any real value to calculate the hyperbolic tangent of.
20+ * @returns {number} hyperbolic tangent
21+ * @constructor
22+ */
23+var TANH = function (...values) : number {
24+  checkArgumentsLength(values, 1);
25+  var rad = firstValueAsNumber(values[0]);
26+  return Math["tanh"](rad);
27+};
28+
29+
30 var TRUNC = Formula["TRUNC"];
31 var XOR = Formula["XOR"];
32 var YEARFRAC = Formula["YEARFRAC"];
33diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
34index 8c7c076..5949415 100644
35--- a/tests/FormulasTest.ts
36+++ b/tests/FormulasTest.ts
37@@ -934,8 +934,27 @@ assertEquals(TAN([1, 44]), 1.5574077246549023);
38 assertEquals(TAN([1, "str"]), 1.5574077246549023);
39 
40 
41+// Test TANH
42+assertEquals(TANH(0), 0);
43+assertEquals(TANH(1), 0.7615941559557649);
44+assertEquals(TANH(PI() / 2), 0.9171523356672744);
45+assertEquals(TANH(PI()), 0.9962720762207501);
46+assertEquals(TANH(false), 0);
47+assertEquals(TANH(true), 0.7615941559557649);
48+assertEquals(TANH(""), 0);
49+assertEquals(TANH("0"), 0);
50+catchAndAssertEquals(function() {
51+  TANH("str");
52+}, ERRORS.VALUE_ERROR);
53+catchAndAssertEquals(function() {
54+  TANH();
55+}, ERRORS.NA_ERROR);
56+catchAndAssertEquals(function() {
57+  TANH(1, 1);
58+}, ERRORS.NA_ERROR);
59+assertEquals(TANH([1, 44]), 0.7615941559557649);
60+assertEquals(TANH([1, "str"]), 0.7615941559557649);
61 
62-assertEquals(TANH(PI()), 0.99627207622075);
63 
64 assertEquals(TRUE(), true);
65 
66diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
67index 2bc8e13..1d30336 100644
68--- a/tests/SheetFormulaTest.ts
69+++ b/tests/SheetFormulaTest.ts
70@@ -466,7 +466,7 @@ testFormula('=TAN(PI() / 2)', 16331239353195370);
71 testFormula('=TAN(PI())', 0);
72 
73 // Test TANH
74-testFormula('=TANH(PI())', 0.99627207622075);
75+testFormula('=TANH(PI())', 0.9962720762207501);
76 
77 // Test TRUE
78 testFormula('=TRUE()', true);