spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Added Formula.FISHERINV
author
Ben Vogt <[email protected]>
date
2017-02-18 18:39:51
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 5ad4add..d17701a 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -128,7 +128,6 @@ var __COMPLEX = {
 6   "F.DIST": Formula["FDIST"],
 7   "F.INV": Formula["FINV"]
 8 };
 9-var FISHERINV = Formula["FISHERINV"];
10 var SUMPRODUCT = Formula["SUMPRODUCT"];
11 var SUMX2MY2 = Formula["SUMX2MY2"];
12 var SUMX2PY2 = Formula["SUMX2PY2"];
13@@ -150,6 +149,20 @@ var FISHER = function (...values) : number {
14   return Math.log((1 + x) / (1 - x)) / 2;
15 };
16 
17+/**
18+ * Returns the inverse Fisher transformation of a specified value.
19+ * @param values[0] value - The value for which to calculate the inverse Fisher transformation.
20+ * @returns {number} inverse Fisher transformation
21+ * @constructor
22+ */
23+var FISHERINV = function (...values) : number {
24+  ArgsChecker.checkLength(values, 1);
25+  var y = TypeCaster.firstValueAsNumber(values[0]);
26+  var e2y = Math.exp(2 * y);
27+  return (e2y - 1) / (e2y + 1);
28+};
29+
30+
31 
32 
33 export {
34diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
35index 8e3eaaf..178a5b4 100644
36--- a/tests/FormulasTest.ts
37+++ b/tests/FormulasTest.ts
38@@ -915,7 +915,25 @@ catchAndAssertEquals(function() {
39 }, ERRORS.NA_ERROR);
40 
41 
42+// Test FISHERINV
43 assertEquals(FISHERINV(0.962), 0.7451676440945232);
44+assertEquals(FISHERINV(0.962), 0.7451676440945232);
45+assertEquals(FISHERINV([0.962]), 0.7451676440945232);
46+assertEquals(FISHERINV("0.962"), 0.7451676440945232);
47+assertEquals(FISHERINV(0), 0);
48+assertEquals(FISHERINV(false), 0);
49+assertEquals(FISHERINV(true), 0.761594155955765);
50+assertEquals(FISHERINV(0.92), 0.7258974148490807);
51+catchAndAssertEquals(function() {
52+  FISHER("str");
53+}, ERRORS.VALUE_ERROR);
54+catchAndAssertEquals(function() {
55+  FISHER();
56+}, ERRORS.NA_ERROR);
57+catchAndAssertEquals(function() {
58+  FISHER(0.55, 0.1);
59+}, ERRORS.NA_ERROR);
60+
61 
62 // Test FLOOR
63 assertEquals(FLOOR(10.1), 10);