spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[NORMSDIST] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-07-03 19:24:22
stats
7 file(s) changed, 70 insertions(+), 5 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Statistical.js
src/Formulas/AllFormulas.ts
src/Formulas/Statistical.ts
tests/Formulas/StatisticalTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 4135a3f..e6c168b 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -1749,6 +1749,15 @@
  6 @returns {number} 
  7 @constructor
  8 ```
  9+
 10+### NORMSDIST 
 11+
 12+```
 13+  Returns the standard normal cumulative distribution for the given number. 
 14+@param z - Value to use in calculation. 
 15+@returns {number} 
 16+@constructor
 17+```
 18 ## Text
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index 48dd3d5..f591d1d 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -71,7 +71,6 @@ For example 64 tbs to a qt.
 26 * NEGBINOMDIST
 27 * NORMDIST
 28 * NORMINV
 29-* NORMSDIST
 30 * PERMUT
 31 * PROB
 32 * RANK
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index 35f07c0..5f8892e 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -159,6 +159,7 @@ exports.POISSON = Statistical_1.POISSON;
 38 exports.PERCENTRANK = Statistical_1.PERCENTRANK;
 39 exports.PERCENTRANK$EXC = Statistical_1.PERCENTRANK$EXC;
 40 exports.NORMSINV = Statistical_1.NORMSINV;
 41+exports.NORMSDIST = Statistical_1.NORMSDIST;
 42 var Text_1 = require("./Text");
 43 exports.ARABIC = Text_1.ARABIC;
 44 exports.CHAR = Text_1.CHAR;
 45diff --git a/dist/Formulas/Statistical.js b/dist/Formulas/Statistical.js
 46index 761e5fc..b7ccb11 100644
 47--- a/dist/Formulas/Statistical.js
 48+++ b/dist/Formulas/Statistical.js
 49@@ -1101,3 +1101,18 @@ var NORMSINV = function (probability) {
 50     return inv(probability, 0, 1);
 51 };
 52 exports.NORMSINV = NORMSINV;
 53+/**
 54+ * Returns the standard normal cumulative distribution for the given number.
 55+ * @param z - Value to use in calculation.
 56+ * @returns {number}
 57+ * @constructor
 58+ */
 59+var NORMSDIST = function (z) {
 60+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "NORMSDIST");
 61+    z = TypeConverter_1.TypeConverter.firstValueAsNumber(z);
 62+    function _cdf(x, mValue, stdVal) {
 63+        return 0.5 * (1 + MathHelpers_1.erf((x - mValue) / Math.sqrt(2 * stdVal * stdVal)));
 64+    }
 65+    return _cdf(z, 0, 1);
 66+};
 67+exports.NORMSDIST = NORMSDIST;
 68diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 69index 5268505..4f18269 100644
 70--- a/src/Formulas/AllFormulas.ts
 71+++ b/src/Formulas/AllFormulas.ts
 72@@ -164,7 +164,8 @@ import {
 73   POISSON,
 74   PERCENTRANK,
 75   PERCENTRANK$EXC,
 76-  NORMSINV
 77+  NORMSINV,
 78+  NORMSDIST
 79 } from "./Statistical";
 80 import {
 81   ARABIC,
 82@@ -400,5 +401,6 @@ export {
 83   POISSON,
 84   PERCENTRANK,
 85   PERCENTRANK$EXC,
 86-  NORMSINV
 87+  NORMSINV,
 88+  NORMSDIST
 89 }
 90\ No newline at end of file
 91diff --git a/src/Formulas/Statistical.ts b/src/Formulas/Statistical.ts
 92index fdc811c..f45a4ab 100644
 93--- a/src/Formulas/Statistical.ts
 94+++ b/src/Formulas/Statistical.ts
 95@@ -1095,6 +1095,22 @@ var NORMSINV = function (probability) {
 96 };
 97 
 98 
 99+/**
100+ * Returns the standard normal cumulative distribution for the given number.
101+ * @param z - Value to use in calculation.
102+ * @returns {number}
103+ * @constructor
104+ */
105+var NORMSDIST = function (z) {
106+  ArgsChecker.checkLength(arguments, 1, "NORMSDIST");
107+  z = TypeConverter.firstValueAsNumber(z);
108+  function _cdf(x, mValue, stdVal) {
109+    return 0.5 * (1 + erf((x - mValue) / Math.sqrt(2 * stdVal * stdVal)));
110+  }
111+  return _cdf(z, 0, 1);
112+};
113+
114+
115 export {
116   AVERAGE,
117   AVERAGEA,
118@@ -1132,5 +1148,6 @@ export {
119   POISSON,
120   PERCENTRANK,
121   PERCENTRANK$EXC,
122-  NORMSINV
123+  NORMSINV,
124+  NORMSDIST
125 }
126\ No newline at end of file
127diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
128index f9bf91e..7550095 100644
129--- a/tests/Formulas/StatisticalTest.ts
130+++ b/tests/Formulas/StatisticalTest.ts
131@@ -35,7 +35,8 @@ import {
132   POISSON,
133   PERCENTRANK,
134   PERCENTRANK$EXC,
135-  NORMSINV
136+  NORMSINV,
137+  NORMSDIST
138 } from "../../src/Formulas/Statistical";
139 import * as ERRORS from "../../src/Errors";
140 import {
141@@ -761,4 +762,22 @@ test("NORMSINV", function() {
142   catchAndAssertEquals(function() {
143     NORMSINV(1);
144   }, ERRORS.NUM_ERROR);
145+  catchAndAssertEquals(function() {
146+    NORMSINV.apply(this, [1, 2]);
147+  }, ERRORS.NA_ERROR);
148+});
149+
150+
151+test("NORMSDIST", function() {
152+  assertEquals(NORMSDIST(0.1), 0.5398278372770289);
153+  assertEquals(NORMSDIST(0.4), 0.6554217416103242);
154+  assertEquals(NORMSDIST(1), 0.8413447460685429);
155+  assertEquals(NORMSDIST(11), 1);
156+  assertEquals(NORMSDIST(-11), 0);
157+  catchAndAssertEquals(function() {
158+    NORMSDIST.apply(this, []);
159+  }, ERRORS.NA_ERROR);
160+  catchAndAssertEquals(function() {
161+    NORMSDIST.apply(this, [1, 2]);
162+  }, ERRORS.NA_ERROR);
163 });
164\ No newline at end of file