Skip to content

Commit

Permalink
[PTRun][Calculator]Add support for log2 and log10 (#24137)
Browse files Browse the repository at this point in the history
* Add support for log2 and log10 in run

* Remove test case as it did not make much sense
  • Loading branch information
RickLuiken committed Feb 22, 2023
1 parent c819b28 commit 3828ac6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -74,6 +74,8 @@ public void Interpret_NoResult_WhenCalled(string input)
new object[] { "e*2", 5.43656365691809M },
new object[] { "ln(3)", 1.09861228866810M },
new object[] { "log(3)", 0.47712125471966M },
new object[] { "log2(3)", 1.58496250072116M },
new object[] { "log10(3)", 0.47712125471966M },
new object[] { "ln(e)", 1M },
new object[] { "cosh(0)", 1M },
};
Expand Down Expand Up @@ -166,6 +168,10 @@ public void Interpret_DifferentCulture_WhenCalled(string input, decimal expected
[DataTestMethod]
[DataRow("log(3)", true)]
[DataRow("ln(3)", true)]
[DataRow("log2(3)", true)]
[DataRow("log10(3)", true)]
[DataRow("log2", false)]
[DataRow("log10", false)]
[DataRow("log", false)]
[DataRow("ln", false)]
[DataRow("ceil(2 * (pi ^ 2))", true)]
Expand Down
Expand Up @@ -12,7 +12,7 @@ public static class CalculateHelper
private static readonly Regex RegValidExpressChar = new Regex(
@"^(" +
@"%|" +
@"ceil\s*\(|floor\s*\(|exp\s*\(|max\s*\(|min\s*\(|abs\s*\(|log\s*\(|ln\s*\(|sqrt\s*\(|pow\s*\(|" +
@"ceil\s*\(|floor\s*\(|exp\s*\(|max\s*\(|min\s*\(|abs\s*\(|log(?:2|10)?\s*\(|ln\s*\(|sqrt\s*\(|pow\s*\(|" +
@"factorial\s*\(|sign\s*\(|round\s*\(|rand\s*\(|" +
@"sin\s*\(|cos\s*\(|tan\s*\(|arcsin\s*\(|arccos\s*\(|arctan\s*\(|" +
@"sinh\s*\(|cosh\s*\(|tanh\s*\(|arsinh\s*\(|arcosh\s*\(|artanh\s*\(|" +
Expand Down

0 comments on commit 3828ac6

Please sign in to comment.