spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[GAMMALN] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-10 04:11:59
stats
8 file(s) changed, 72 insertions(+), 7 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Math.js
src/Formulas/AllFormulas.ts
src/Formulas/Math.ts
tests/Formulas/MathTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 83b793a..d1e2ff3 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -541,6 +541,15 @@
  6 @constructor
  7 ```
  8 
  9+### GAMMALN 
 10+
 11+```
 12+  Returns the the logarithm of a specified Gamma function, base e (Euler's number). 
 13+@param value - The input number. The natural logarithm of Gamma (value) will be returned. Must be positive. 
 14+@returns {number} 
 15+@constructor
 16+```
 17+
 18 ### ABS 
 19 
 20 ```
 21diff --git a/TODO.md b/TODO.md
 22index 2c0eac1..99c1cab 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -56,7 +56,6 @@ For example 64 tbs to a qt.
 26 * VLOOKUP
 27 * COUNTBLANK
 28 * FACTDOUBLE
 29-* GAMMALN
 30 * MROUND
 31 * MULTINOMIAL
 32 * PRODUCT
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index 8fb6d1d..0b91a1c 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -66,6 +66,7 @@ exports.LTE = Math_1.LTE;
 38 exports.NE = Math_1.NE;
 39 exports.GCD = Math_1.GCD;
 40 exports.LCM = Math_1.LCM;
 41+exports.GAMMALN = Math_1.GAMMALN;
 42 var Info_1 = require("./Info");
 43 exports.NA = Info_1.NA;
 44 var Lookup_1 = require("./Lookup");
 45diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
 46index e7721c5..e393a95 100644
 47--- a/dist/Formulas/Math.js
 48+++ b/dist/Formulas/Math.js
 49@@ -57,6 +57,21 @@ var LCM = function () {
 50     return r;
 51 };
 52 exports.LCM = LCM;
 53+/**
 54+ *
 55+ * @param value
 56+ * @returns {number}
 57+ * @constructor
 58+ */
 59+var GAMMALN = function (value) {
 60+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "GAMMALN");
 61+    var x = TypeConverter_1.TypeConverter.firstValueAsNumber(value);
 62+    if (x <= 0) {
 63+        throw new Errors_1.NumError("Function GAMMALN parameter 1 value is " + x + ". It should be greater than 0.");
 64+    }
 65+    return MathHelpers_1.gammaln(x);
 66+};
 67+exports.GAMMALN = GAMMALN;
 68 /**
 69  * Returns the absolute value of a number.
 70  * @param value to get the absolute value of.
 71diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 72index 962e5fc..485ef19 100644
 73--- a/src/Formulas/AllFormulas.ts
 74+++ b/src/Formulas/AllFormulas.ts
 75@@ -63,7 +63,8 @@ import {
 76   LTE,
 77   NE,
 78   GCD,
 79-  LCM
 80+  LCM,
 81+  GAMMALN
 82 } from "./Math";
 83 import {
 84   NA
 85@@ -305,5 +306,6 @@ export {
 86   CHOOSE,
 87   GCD,
 88   TRIM,
 89-  LCM
 90+  LCM,
 91+  GAMMALN
 92 }
 93\ No newline at end of file
 94diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
 95index cdab882..b555e11 100644
 96--- a/src/Formulas/Math.ts
 97+++ b/src/Formulas/Math.ts
 98@@ -21,7 +21,7 @@ import {
 99   NAError
100 } from "../Errors";
101 import {
102-  erf
103+  erf, gammaln
104 } from "../Utilities/MathHelpers";
105 
106 
107@@ -68,6 +68,22 @@ var LCM =  function (...values) {
108 };
109 
110 
111+/**
112+ * Returns the the logarithm of a specified Gamma function, base e (Euler's number).
113+ * @param value - The input number. The natural logarithm of Gamma (value) will be returned. Must be positive.
114+ * @returns {number}
115+ * @constructor
116+ */
117+var GAMMALN = function (value) {
118+  ArgsChecker.checkLength(arguments, 1, "GAMMALN");
119+  var x =  TypeConverter.firstValueAsNumber(value);
120+  if (x <= 0) {
121+    throw new NumError("Function GAMMALN parameter 1 value is " + x + ". It should be greater than 0.");
122+  }
123+  return gammaln(x);
124+};
125+
126+
127 /**
128  * Returns the absolute value of a number.
129  * @param value to get the absolute value of.
130@@ -1286,5 +1302,6 @@ export {
131   LTE,
132   NE,
133   GCD,
134-  LCM
135+  LCM,
136+  GAMMALN
137 }
138\ No newline at end of file
139diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
140index 48994b0..8337f7e 100644
141--- a/tests/Formulas/MathTest.ts
142+++ b/tests/Formulas/MathTest.ts
143@@ -63,7 +63,8 @@ import {
144   LTE,
145   NE,
146   GCD,
147-  LCM
148+  LCM,
149+  GAMMALN
150 } from "../../src/Formulas/Math";
151 import * as ERRORS from "../../src/Errors";
152 import {
153@@ -73,6 +74,21 @@ import {
154 } from "../Utils/Asserts";
155 
156 
157+test("GAMMALN", function(){
158+  assertEquals(GAMMALN(4.5), 2.453736570842444);
159+  assertEquals(GAMMALN(3), 0.6931471805599443);
160+  catchAndAssertEquals(function() {
161+    GAMMALN(0)
162+  }, ERRORS.NUM_ERROR);
163+  catchAndAssertEquals(function() {
164+    GAMMALN.apply(this, []);
165+  }, ERRORS.NA_ERROR);
166+  catchAndAssertEquals(function() {
167+    GAMMALN.apply(this, [10, 10]);
168+  }, ERRORS.NA_ERROR);
169+});
170+
171+
172 test("LCM", function(){
173   assertEquals(LCM(2, 5), 10);
174   assertEquals(LCM(10, 100), 100);
175@@ -83,6 +99,7 @@ test("LCM", function(){
176   }, ERRORS.NA_ERROR);
177 });
178 
179+
180 test("GCD", function(){
181   assertEquals(GCD(10, 100), 10);
182   assertEquals(GCD(22, 44), 22);
183diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
184index c8370fb..824b510 100644
185--- a/tests/SheetFormulaTest.ts
186+++ b/tests/SheetFormulaTest.ts
187@@ -255,6 +255,10 @@ test("Sheet LCM", function(){
188   assertFormulaEquals('=LCM(2, 5)', 10);
189 });
190 
191+test("Sheet GAMMALN", function(){
192+  assertFormulaEquals('=GAMMALN(4.5)', 2.453736570842444);
193+});
194+
195 test("Sheet DELTA", function(){
196   assertFormulaEquals('=DELTA(2, 2)', 1);
197 });