commit
message
Formulas.TAN written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-04 18:07:23
stats
2 file(s) changed,
30 insertions(+),
1 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index 80c1f55..44876b9 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -141,9 +141,19 @@ var SUMPRODUCT = Formula["SUMPRODUCT"];
6 var SUMSQ = Formula["SUMSQ"];
7 var SUMX2MY2 = Formula["SUMX2MY2"];
8 var SUMX2PY2 = Formula["SUMX2PY2"];
9-var TAN = function (rad) {
10+
11+/**
12+ * Returns the tangent of an angle provided in radians.
13+ * @param values The angle to find the tangent of, in radians.
14+ * @returns {number} tangent in radians
15+ * @constructor
16+ */
17+var TAN = function (...values) {
18+ checkArgumentsLength(values, 1);
19+ var rad = firstValueAsNumber(values[0]);
20 return rad === Math.PI ? 0 : Math.tan(rad);
21 };
22+
23 var TANH = Formula["TANH"];
24 var TRUNC = Formula["TRUNC"];
25 var XOR = Formula["XOR"];
26diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
27index e98a0f0..8c7c076 100644
28--- a/tests/FormulasTest.ts
29+++ b/tests/FormulasTest.ts
30@@ -912,10 +912,28 @@ assertEquals(SUMX2MY2([1,2,3],[4,5,6]), -63);
31
32 assertEquals(SUMX2PY2([1, 2, 3], [4, 5, 6]), 91);
33
34+// Test TAN
35 assertEquals(TAN(0), 0);
36 assertEquals(TAN(1), 1.5574077246549023);
37 assertEquals(TAN(PI() / 2), 16331239353195370);
38 assertEquals(TAN(PI()), 0);
39+assertEquals(TAN(false), 0);
40+assertEquals(TAN(true), 1.5574077246549023);
41+assertEquals(TAN(""), 0);
42+assertEquals(TAN("0"), 0);
43+catchAndAssertEquals(function() {
44+ TAN("str");
45+}, ERRORS.VALUE_ERROR);
46+catchAndAssertEquals(function() {
47+ TAN();
48+}, ERRORS.NA_ERROR);
49+catchAndAssertEquals(function() {
50+ TAN(1, 1);
51+}, ERRORS.NA_ERROR);
52+assertEquals(TAN([1, 44]), 1.5574077246549023);
53+assertEquals(TAN([1, "str"]), 1.5574077246549023);
54+
55+
56
57 assertEquals(TANH(PI()), 0.99627207622075);
58