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.RADIANS
author
Ben Vogt <[email protected]>
date
2017-02-18 01:18:06
stats
2 file(s) changed, 29 insertions(+), 1 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index f539e5d..0a8dec7 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -132,6 +132,17 @@ var SUMX2MY2 = Formula["SUMX2MY2"];
 6 var SUMX2PY2 = Formula["SUMX2PY2"];
 7 var YEARFRAC = Formula["YEARFRAC"];
 8 
 9+/**
10+ * Converts an angle value in degrees to radians.
11+ * @param values[0] angle - The angle to convert from degrees to radians.
12+ * @returns {number} radians
13+ * @constructor
14+ */
15+var RADIANS = function (...values) {
16+  ArgsChecker.checkLength(values, 1);
17+  var d = TypeCaster.firstValueAsNumber(values[0]);
18+  return d * Math.PI / 180;
19+};
20 
21 /**
22  * Converts an angle value in radians to degrees.
23@@ -433,5 +444,6 @@ export {
24   TANH,
25   TRUNC,
26   XOR,
27-  YEARFRAC
28+  YEARFRAC,
29+  RADIANS
30 }
31\ No newline at end of file
32diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
33index f7731e0..84a0503 100644
34--- a/tests/FormulasTest.ts
35+++ b/tests/FormulasTest.ts
36@@ -6,7 +6,7 @@ import { ABS, ACCRINT, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2
37     DB, DDB, DEC2BIN, DEC2HEX, DEC2OCT, DEGREES, DELTA, DEVSQ, DOLLAR, DOLLARDE, DOLLARFR, EDATE,
38     EFFECT, EOMONTH, ERF, ERFC, EVEN, EXACT, EXPONDIST, FALSE, FLOOR, __COMPLEX, FISHER, FISHERINV, IF,
39     INT, ISEVEN, ISODD, LN, LOG, LOG10, MAX, MAXA, MEDIAN, MIN, MINA, MOD, NOT, TRUE, ODD, OR,
40-    POWER, ROUND, ROUNDDOWN, ROUNDUP, SIN, SINH, SPLIT, SQRT, SQRTPI, SUM, SUMIF, SUMPRODUCT,
41+    POWER, ROUND, ROUNDDOWN, ROUNDUP, SIN, SINH, SPLIT, SQRT, SQRTPI, SUM, SUMIF, SUMPRODUCT, RADIANS,
42     SUMSQ, SUMX2MY2, SUMX2PY2, TAN, TANH, TRUNC, XOR, YEARFRAC } from "../src/RawFormulas/RawFormulas"
43 import * as ERRORS from "../src/Errors"
44 import {assertEquals, assertEqualsDates, assertArrayEquals} from "./utils/Asserts"
45@@ -1210,6 +1210,21 @@ catchAndAssertEquals(function() {
46 }, ERRORS.NA_ERROR);
47 
48 
49+// Test RADIANS
50+assertEquals(RADIANS(180), 3.141592653589793);
51+assertEquals(RADIANS(false), 0);
52+assertEquals(RADIANS(true), 0.017453292519943295);
53+catchAndAssertEquals(function() {
54+  RADIANS("str");
55+}, ERRORS.VALUE_ERROR);
56+catchAndAssertEquals(function() {
57+  RADIANS();
58+}, ERRORS.NA_ERROR);
59+catchAndAssertEquals(function() {
60+  RADIANS(4, 10);
61+}, ERRORS.NA_ERROR);
62+
63+
64 // Test ROUND
65 assertEquals(ROUND(99.44, 1), 99.4);
66 assertEquals(ROUND(99.44, 0), 99);