spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.LN written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-05 22:33:20
stats
3 file(s) changed, 37 insertions(+), 4 deletions(-)
files
src/RawFormulas/Math.ts
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
  1diff --git a/src/RawFormulas/Math.ts b/src/RawFormulas/Math.ts
  2index 3b5c7ad..7785894 100644
  3--- a/src/RawFormulas/Math.ts
  4+++ b/src/RawFormulas/Math.ts
  5@@ -672,6 +672,21 @@ var LOG = function (...values) : number {
  6   return ln / lb;
  7 };
  8 
  9+/**
 10+ * Returns the logarithm of a number, base e (Euler's number).
 11+ * @param values[0] The value for which to calculate the logarithm, base e.
 12+ * @returns {number} logarithm calculated
 13+ * @constructor
 14+ */
 15+var LN = function (...values) : number {
 16+  checkArgumentsLength(values, 1);
 17+  var n = firstValueAsNumber(values[0]);
 18+  if (n < 1) {
 19+    throw new CellError(ERRORS.NUM_ERROR, "Function LN parameter 1 value is " + n + ". It should be greater than 0.");
 20+  }
 21+  return Math.log(n);
 22+};
 23+
 24 /**
 25  * Returns the tangent of an angle provided in radians.
 26  * @param values The angle to find the tangent of, in radians.
 27@@ -733,6 +748,7 @@ export {
 28   POWER,
 29   LOG,
 30   LOG10,
 31+  LN,
 32   TAN,
 33   TANH
 34 }
 35\ No newline at end of file
 36diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 37index c465157..3083261 100644
 38--- a/src/RawFormulas/RawFormulas.ts
 39+++ b/src/RawFormulas/RawFormulas.ts
 40@@ -38,6 +38,7 @@ import {
 41   POWER,
 42   LOG,
 43   LOG10,
 44+  LN,
 45   TAN,
 46   TANH
 47 } from "./Math";
 48@@ -140,7 +141,6 @@ var __COMPLEX = {
 49 var FISHER = Formula["FISHER"];
 50 var FISHERINV = Formula["FISHERINV"];
 51 var IF = Formula["IF"];
 52-var LN = Formula["LN"];
 53 var ROUND = Formula["ROUND"];
 54 var ROUNDDOWN = Formula["ROUNDDOWN"];
 55 var ROUNDUP = Formula["ROUNDUP"];
 56@@ -152,6 +152,7 @@ var SUMSQ = Formula["SUMSQ"];
 57 var SUMX2MY2 = Formula["SUMX2MY2"];
 58 var SUMX2PY2 = Formula["SUMX2PY2"];
 59 var TRUNC = Formula["TRUNC"];
 60+var YEARFRAC = Formula["YEARFRAC"];
 61 
 62 /**
 63  * Exclusive or or exclusive disjunction is a logical operation that outputs true only when inputs differ.
 64@@ -183,8 +184,6 @@ var XOR = function (...values) {
 65   return alreadyTruthy;
 66 };
 67 
 68-var YEARFRAC = Formula["YEARFRAC"];
 69-
 70 export {
 71   __COMPLEX,
 72 
 73diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
 74index 1f54db8..3b8cc2c 100644
 75--- a/tests/FormulasTest.ts
 76+++ b/tests/FormulasTest.ts
 77@@ -634,7 +634,24 @@ catchAndAssertEquals(function() {
 78   ISODD("");
 79 }, ERRORS.VALUE_ERROR);
 80 
 81+
 82+// Test LN
 83 assertEquals(LN(100), 4.605170185988092);
 84+assertEquals(LN("100"), 4.605170185988092);
 85+assertEquals(LN(1), 0);
 86+assertEquals(LN(true), 0);
 87+catchAndAssertEquals(function() {
 88+  LN(false);
 89+}, ERRORS.NUM_ERROR);
 90+catchAndAssertEquals(function() {
 91+  LN("str");
 92+}, ERRORS.VALUE_ERROR);
 93+catchAndAssertEquals(function() {
 94+  LN();
 95+}, ERRORS.NA_ERROR);
 96+catchAndAssertEquals(function() {
 97+  LN(10, 10);
 98+}, ERRORS.NA_ERROR);
 99 
100 
101 // Test LOG