commit
message
Formulas.ACOTH written and tested.
author
Ben Vogt <[email protected]>
date
2017-01-16 21:54:55
stats
2 file(s) changed,
30 insertions(+),
1 deletions(-)
files
src/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas.ts b/src/RawFormulas.ts
2index 9c81885..f0dbc93 100644
3--- a/src/RawFormulas.ts
4+++ b/src/RawFormulas.ts
5@@ -144,7 +144,22 @@ var ACOSH = function (value?) {
6 return Math.log(value + Math.sqrt(value * value - 1));
7 };
8
9-var ACOTH = Formula["ACOTH"];
10+/**
11+ * Calculate the hyperbolic arc-cotangent of a value
12+ * @param value number not between -1 and 1 inclusively.
13+ * @returns {number} hyperbolic arc-cotangent
14+ * @constructor
15+ */
16+var ACOTH = function (value?) {
17+ checkArgumentsLength(arguments, 1);
18+ value = valueToNumber(value);
19+ if (value <= 1 && value >= -1) {
20+ throw new CellError(ERRORS.NUM_ERROR, "Function ____ parameter 1 value is " + value + ". Valid values cannot be between -1 and 1 inclusive.")
21+ }
22+ return 0.5 * Math.log((value + 1) / (value - 1));
23+};
24+
25+
26 var AND = Formula["AND"];
27 var ARABIC = Formula["ARABIC"];
28 var ASIN = Formula["ASIN"];
29diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
30index b639efa..9f02a4b 100644
31--- a/tests/FormulasTest.ts
32+++ b/tests/FormulasTest.ts
33@@ -70,7 +70,20 @@ catchAndAssertEquals(function() {
34 }, ERRORS.NUM_ERROR);
35
36
37+// Test ACOTH
38 assertEquals(ACOTH(22), 0.04548588910286339);
39+assertEquals(ACOTH(-1.1), -1.522261218861711);
40+assertEquals(ACOTH("-22"), -0.04548588910286338);
41+catchAndAssertEquals(function() {
42+ return ACOTH(-1);
43+}, ERRORS.NUM_ERROR);
44+catchAndAssertEquals(function() {
45+ return ACOTH("str");
46+}, ERRORS.VALUE_ERROR);
47+catchAndAssertEquals(function() {
48+ return ACOTH(false);
49+}, ERRORS.NUM_ERROR);
50+
51
52 assertEquals(AND(10, 10), true);
53 assertEquals(AND(10, 0), false);