spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Added Formulas.DEGREES
author
Ben Vogt <[email protected]>
date
2017-02-18 01:08:14
stats
2 file(s) changed, 29 insertions(+), 2 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 614cd89..f539e5d 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -105,7 +105,6 @@ var DAYS = Formula["DAYS"];
 6 var DAYS360 = Formula["DAYS360"];
 7 var DB = Formula["DB"];
 8 var DDB = Formula["DDB"];
 9-var DEGREES = Formula["DEGREES"];
10 var DEVSQ = Formula["DEVSQ"];
11 var DOLLAR = Formula["DOLLAR"];
12 var DOLLARDE = Formula["DOLLARDE"];
13@@ -133,6 +132,20 @@ var SUMX2MY2 = Formula["SUMX2MY2"];
14 var SUMX2PY2 = Formula["SUMX2PY2"];
15 var YEARFRAC = Formula["YEARFRAC"];
16 
17+
18+/**
19+ * Converts an angle value in radians to degrees.
20+ * @param values[0] angle - The angle to convert from radians to degrees.
21+ * @returns {number} degrees
22+ * @constructor
23+ */
24+var DEGREES = function (...values) {
25+  ArgsChecker.checkLength(values, 1);
26+  var r = TypeCaster.firstValueAsNumber(values[0]);
27+  return r * 180 / Math.PI;
28+};
29+
30+
31 /**
32  * Converts a decimal number to signed octal format.
33  * @param values[0] decimal_number - The decimal value to be converted to signed octal,provided as a string. For this
34diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
35index dc20db3..f7731e0 100644
36--- a/tests/FormulasTest.ts
37+++ b/tests/FormulasTest.ts
38@@ -713,7 +713,22 @@ catchAndAssertEquals(function() {
39 }, ERRORS.VALUE_ERROR);
40 
41 
42+// Test DEGREES
43 assertEquals(DEGREES(PI()), 180);
44+assertEquals(DEGREES([PI(), "str"]), 180);
45+assertEquals(DEGREES(false), 0);
46+assertEquals(DEGREES(true), 57.29577951308232);
47+assertEquals(DEGREES(1), 57.29577951308232);
48+assertEquals(DEGREES(12), 687.5493541569879);
49+catchAndAssertEquals(function() {
50+  DEGREES("str");
51+}, ERRORS.VALUE_ERROR);
52+catchAndAssertEquals(function() {
53+  DEGREES();
54+}, ERRORS.NA_ERROR);
55+catchAndAssertEquals(function() {
56+  DEGREES(10, 10);
57+}, ERRORS.NA_ERROR);
58 
59 
60 // Test DELTA