commit
message
Formulas.ATANH written and tested.
author
Ben Vogt <[email protected]>
date
2017-01-17 00:35:50
stats
3 file(s) changed,
33 insertions(+),
1 deletions(-)
files
src/RawFormulas.ts
tests/FormulasTest.ts
tests/SheetFormulaTest.ts
1diff --git a/src/RawFormulas.ts b/src/RawFormulas.ts
2index 78f1356..6f83320 100644
3--- a/src/RawFormulas.ts
4+++ b/src/RawFormulas.ts
5@@ -294,7 +294,25 @@ var ATAN2 = function (x, y) {
6 };
7
8
9-var ATANH = Formula["ATANH"];
10+/**
11+ * Returns the inverse hyperbolic tangent of a number.
12+ * @param value The value for which to calculate the inverse hyperbolic tangent. Must be between -1 and 1, exclusive.
13+ * @returns {number} inverse hyperbolic tangent of input
14+ * @constructor
15+ */
16+var ATANH = function (value?) : number {
17+ checkArgumentsLength(arguments, 1);
18+ value = valueToNumber(value);
19+ if (value >= 1 || value <= -1) {
20+ throw new CellError(ERRORS.NUM_ERROR, "Function ATANH parameter 1 value is " + value + ". Valid values are between -1 and 1 exclusive.");
21+ }
22+ if (Math.abs(value) < 1) {
23+
24+ }
25+ return Math["atanh"](value);
26+};
27+
28+
29 var AVEDEV = Formula["AVEDEV"];
30 var AVERAGE = Formula["AVERAGE"];
31 var AVERAGEA = Formula["AVERAGEA"];
32diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
33index f620e00..a312b02 100644
34--- a/tests/FormulasTest.ts
35+++ b/tests/FormulasTest.ts
36@@ -170,7 +170,20 @@ catchAndAssertEquals(function() {
37 return ATAN2("str", false);
38 }, ERRORS.VALUE_ERROR);
39
40+
41+// Test ATANH
42+assertEquals(ATANH(0.51), 0.5627297693521489);
43 assertEquals(ATANH(0.44), 0.47223080442042564);
44+assertEquals(ATANH(0), 0);
45+assertEquals(ATANH("0.1"), 0.10033534773107562);
46+assertEquals(ATANH(false), 0);
47+catchAndAssertEquals(function() {
48+ return ATANH(true);
49+}, ERRORS.NUM_ERROR);
50+catchAndAssertEquals(function() {
51+ return ATANH("str");
52+}, ERRORS.VALUE_ERROR);
53+
54
55 assertEquals(AVEDEV(1, 2, 4, 56.7), 20.3875);
56
57diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
58index 6816436..8c311a8 100644
59--- a/tests/SheetFormulaTest.ts
60+++ b/tests/SheetFormulaTest.ts
61@@ -66,7 +66,7 @@ testFormula("=ATAN(0.1)", 0.09966865249116204);
62 testFormula("=ATAN2(4, 3)", 0.6435011087932844);
63
64 // Test ATANH
65-testFormula("=ATANH(0.44)", 0.47223080442042564);
66+testFormula("=ATANH(0.51)", 0.5627297693521489);
67
68 // Test AVEDEV
69 testFormula("=AVEDEV(1, 2, 4, 56.7)", 20.3875);