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.SQRTPI
author
Ben Vogt <[email protected]>
date
2017-02-18 06:01:19
stats
2 file(s) changed, 41 insertions(+), 1 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 5f3f58b..459de63 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -124,12 +124,28 @@ var __COMPLEX = {
 6 };
 7 var FISHER = Formula["FISHER"];
 8 var FISHERINV = Formula["FISHERINV"];
 9-var SQRTPI = Formula["SQRTPI"];
10 var SUMPRODUCT = Formula["SUMPRODUCT"];
11 var SUMX2MY2 = Formula["SUMX2MY2"];
12 var SUMX2PY2 = Formula["SUMX2PY2"];
13 var YEARFRAC = Formula["YEARFRAC"];
14 
15+
16+/**
17+ * Returns the positive square root of the product of Pi and the given positive number.
18+ * @param values[0] value - The number which will be multiplied by Pi and have the product's square root returned
19+ * @returns {number} the positive square root of the product of Pi and the given positive number.
20+ * @constructor
21+ */
22+var SQRTPI = function (...values) : number{
23+  ArgsChecker.checkLength(values, 1);
24+  var n = TypeCaster.firstValueAsNumber(values[0]);
25+  if (n < 0) {
26+    throw new CellError(ERRORS.NUM_ERROR, "Function SQRTPI parameter 1 value is " + n + ". It should be greater than or equal to 0.");
27+  }
28+  return Math.sqrt(n * Math.PI);
29+};
30+
31+
32 /**
33  * Converts a signed binary number to decimal format.
34  * @param values[0] signed_binary_number - The signed 10-bit binary value to be converted to decimal, provided as a
35diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
36index 7667234..008c09e 100644
37--- a/tests/FormulasTest.ts
38+++ b/tests/FormulasTest.ts
39@@ -1415,7 +1415,25 @@ catchAndAssertEquals(function() {
40 }, ERRORS.NA_ERROR);
41 
42 
43+// Test SQRTPI
44 assertEquals(SQRTPI(9), 5.317361552716548);
45+assertEquals(SQRTPI("9"), 5.317361552716548);
46+assertEquals(SQRTPI([9]), 5.317361552716548);
47+assertEquals(SQRTPI(0), 0);
48+assertEquals(SQRTPI(1), 1.7724538509055159);
49+assertEquals(SQRTPI(""), 0);
50+catchAndAssertEquals(function() {
51+  SQRTPI("str");
52+}, ERRORS.VALUE_ERROR);
53+catchAndAssertEquals(function() {
54+  SQRTPI(-1);
55+}, ERRORS.NUM_ERROR);
56+catchAndAssertEquals(function() {
57+  SQRTPI();
58+}, ERRORS.NA_ERROR);
59+catchAndAssertEquals(function() {
60+  SQRTPI(4, 4);
61+}, ERRORS.NA_ERROR);
62 
63 
64 // Test SUM