[PTRun][Calculator]Add support for log2 and log10 (#24137)

* Add support for log2 and log10 in run

* Remove test case as it did not make much sense
This commit is contained in:
RickLuiken 2023-02-22 17:25:48 +01:00 committed by GitHub
parent c819b287f3
commit 3828ac6ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -74,6 +74,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
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 },
};
@ -166,6 +168,10 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
[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)]

View File

@ -12,7 +12,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
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*\(|" +