spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[UMINUS] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-13 02:57:57
stats
8 file(s) changed, 62 insertions(+), 3 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 df833c3..bd3b10e 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -1170,6 +1170,15 @@
  6 @returns any value 
  7 @constructor
  8 ```
  9+
 10+### UMINUS 
 11+
 12+```
 13+  Returns the same number, but with the sign reversed. 
 14+@param value to reverse the sign on 
 15+@returns {number} 
 16+@constructor
 17+```
 18 ## Statistical
 19 
 20 
 21diff --git a/TODO.md b/TODO.md
 22index 952fd62..a41d6d5 100644
 23--- a/TODO.md
 24+++ b/TODO.md
 25@@ -60,7 +60,6 @@ For example 64 tbs to a qt.
 26 * MULTINOMIAL
 27 * SERIESSUM
 28 * SUBTOTAL
 29-* UMINUS
 30 * UNARY_PERCENT
 31 * TO_DATE - Contingent upon cells having display formats derived from type-hierarchy
 32 * TO_DOLLARS - Contingent upon cells having display formats derived from type-hierarchy
 33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 34index f6fc9de..d7ec24f 100644
 35--- a/dist/Formulas/AllFormulas.js
 36+++ b/dist/Formulas/AllFormulas.js
 37@@ -70,6 +70,7 @@ exports.GAMMALN = Math_1.GAMMALN;
 38 exports.PRODUCT = Math_1.PRODUCT;
 39 exports.QUOTIENT = Math_1.QUOTIENT;
 40 exports.UPLUS = Math_1.UPLUS;
 41+exports.UMINUS = Math_1.UMINUS;
 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 2692f47..33a2177 100644
 47--- a/dist/Formulas/Math.js
 48+++ b/dist/Formulas/Math.js
 49@@ -1270,3 +1270,15 @@ var UPLUS = function (value) {
 50     return TypeConverter_1.TypeConverter.firstValue(value);
 51 };
 52 exports.UPLUS = UPLUS;
 53+/**
 54+ * Returns the same number, but with the sign reversed.
 55+ * @param value to reverse the sign on
 56+ * @returns {number}
 57+ * @constructor
 58+ */
 59+var UMINUS = function (value) {
 60+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "UMINUS");
 61+    var n = TypeConverter_1.TypeConverter.firstValueAsNumber(value);
 62+    return n * -1;
 63+};
 64+exports.UMINUS = UMINUS;
 65diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 66index b33390d..e058e2c 100644
 67--- a/src/Formulas/AllFormulas.ts
 68+++ b/src/Formulas/AllFormulas.ts
 69@@ -67,7 +67,8 @@ import {
 70   GAMMALN,
 71   PRODUCT,
 72   QUOTIENT,
 73-  UPLUS
 74+  UPLUS,
 75+  UMINUS
 76 } from "./Math";
 77 import {
 78   NA
 79@@ -317,5 +318,6 @@ export {
 80   PERCENTILE,
 81   PRODUCT,
 82   QUOTIENT,
 83-  UPLUS
 84+  UPLUS,
 85+  UMINUS
 86 }
 87\ No newline at end of file
 88diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
 89index a0421c3..6bb9b93 100644
 90--- a/src/Formulas/Math.ts
 91+++ b/src/Formulas/Math.ts
 92@@ -1281,6 +1281,19 @@ var UPLUS = function (value) : any {
 93 };
 94 
 95 
 96+/**
 97+ * Returns the same number, but with the sign reversed.
 98+ * @param value to reverse the sign on
 99+ * @returns {number}
100+ * @constructor
101+ */
102+var UMINUS = function (value) {
103+  ArgsChecker.checkLength(arguments, 1, "UMINUS");
104+  var n = TypeConverter.firstValueAsNumber(value);
105+  return n * -1;
106+};
107+
108+
109 export {
110   ABS,
111   ACOS,
112@@ -1350,5 +1363,6 @@ export {
113   GAMMALN,
114   PRODUCT,
115   QUOTIENT,
116-  UPLUS
117+  UPLUS,
118+  UMINUS
119 }
120\ No newline at end of file
121diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
122index a62b3b3..6799527 100644
123--- a/tests/Formulas/MathTest.ts
124+++ b/tests/Formulas/MathTest.ts
125@@ -67,7 +67,8 @@ import {
126   GAMMALN,
127   PRODUCT,
128   QUOTIENT,
129-  UPLUS
130+  UPLUS,
131+  UMINUS
132 } from "../../src/Formulas/Math";
133 import * as ERRORS from "../../src/Errors";
134 import {
135@@ -114,6 +115,18 @@ test("UPLUS", function(){
136 });
137 
138 
139+test("UMINUS", function(){
140+  assertEquals(UMINUS(2), -2);
141+  assertEquals(UMINUS(-1), 1);
142+  assertEquals(UMINUS(false), 0);
143+  assertEquals(UMINUS(0), 0);
144+  assertEquals(UMINUS([1, 2, 3]), -1);
145+  catchAndAssertEquals(function() {
146+    UMINUS.apply(this, []);
147+  }, ERRORS.NA_ERROR);
148+});
149+
150+
151 test("PRODUCT", function(){
152   assertEquals(PRODUCT(2, 5), 10);
153   assertEquals(PRODUCT(2, 5, 4, 2, 8, 1, 77, 2, 3, 1), 295680);
154diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
155index c1323f2..d08e075 100644
156--- a/tests/SheetFormulaTest.ts
157+++ b/tests/SheetFormulaTest.ts
158@@ -271,6 +271,10 @@ test("Sheet UPLUS", function(){
159   assertFormulaEquals('=UPLUS(8)', 8);
160 });
161 
162+test("Sheet UMINUS", function(){
163+  assertFormulaEquals('=UMINUS(8)', -8);
164+});
165+
166 test("Sheet PERCENTILE", function(){
167   assertFormulaEquals('=PERCENTILE([10], 0)', 10);
168 });