commit
message
Formulas.LOG10 written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-04 22:26:25
stats
2 file(s) changed,
38 insertions(+),
0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index b2f5d6f..8effb7f 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -135,7 +135,24 @@ var FISHER = Formula["FISHER"];
6 var FISHERINV = Formula["FISHERINV"];
7 var IF = Formula["IF"];
8 var LN = Formula["LN"];
9-var LOG10 = Formula["LOG10"];
10+
11+
12+/**
13+ * Returns the the logarithm of a number, base 10.
14+ * @param values[0] The value for which to calculate the logarithm, base 10.
15+ * @returns {number} logarithm of the number, in base 10.
16+ * @constructor
17+ */
18+var LOG10 = function (...values) : number {
19+ checkArgumentsLength(values, 1);
20+ var n = firstValueAsNumber(values[0]);
21+ if (n < 1) {
22+ throw new CellError(ERRORS.NUM_ERROR, "Function LOG10 parameter 1 value is " + n + ". It should be greater than 0.");
23+ }
24+ var ln = Math.log(n);
25+ var lb = Math.log(10);
26+ return ln / lb;
27+};
28
29 /**
30 * Returns the the logarithm of a number given a base.
31diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
32index 16d2965..9f4e3bf 100644
33--- a/tests/FormulasTest.ts
34+++ b/tests/FormulasTest.ts
35@@ -662,8 +662,26 @@ catchAndAssertEquals(function() {
36 }, ERRORS.DIV_ZERO_ERROR);
37
38
39-
40+// Test LOG10
41 assertEquals(LOG10(100), 2);
42+assertEquals(LOG10("100"), 2);
43+assertEquals(LOG10(1), 0);
44+assertEquals(LOG10(10.1), 1.0043213737826424);
45+catchAndAssertEquals(function() {
46+ LOG10(false);
47+}, ERRORS.NUM_ERROR);
48+catchAndAssertEquals(function() {
49+ LOG10("");
50+}, ERRORS.NUM_ERROR);
51+catchAndAssertEquals(function() {
52+ LOG10("str");
53+}, ERRORS.VALUE_ERROR);
54+catchAndAssertEquals(function() {
55+ LOG10();
56+}, ERRORS.NA_ERROR);
57+catchAndAssertEquals(function() {
58+ LOG10(10, 10);
59+}, ERRORS.NA_ERROR);
60
61
62 // Test MAX