From f6daf0b1f6ffe561a057c781b474f733f8e66d96 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Tue, 28 Dec 2021 04:59:31 -0800 Subject: [PATCH] mage has log as ln and then has log10. (#15176) --- .../ExtendedCalculatorParserTests.cs | 10 +++++++--- .../CalculateEngine.cs | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/ExtendedCalculatorParserTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/ExtendedCalculatorParserTests.cs index 0336afe638..32edd69527 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/ExtendedCalculatorParserTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator.UnitTest/ExtendedCalculatorParserTests.cs @@ -72,7 +72,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests new object[] { "exp(5)", 148.413159102577M }, new object[] { "e^5", 148.413159102577M }, new object[] { "e*2", 5.43656365691809M }, - new object[] { "log(e)", 1M }, + new object[] { "ln(3)", 1.09861228866810M }, + new object[] { "log(3)", 0.47712125471966M }, + new object[] { "ln(e)", 1M }, new object[] { "cosh(0)", 1M }, }; @@ -141,6 +143,10 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests } [DataTestMethod] + [DataRow("log(3)", true)] + [DataRow("ln(3)", true)] + [DataRow("log", false)] + [DataRow("ln", false)] [DataRow("ceil(2 * (pi ^ 2))", true)] [DataRow("((1 * 2)", false)] [DataRow("(1 * 2)))", false)] @@ -160,8 +166,6 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests [DataRow("1+1.1e3", true)] public void InputValid_TestValid_WhenCalled(string input, bool valid) { - // Arrange - // Act var result = CalculateHelper.InputValid(input); diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs index 08a17743d0..1ffd6c3179 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/CalculateEngine.cs @@ -34,6 +34,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator return default; } + // mages has quirky log representation + // mage has log == ln vs log10 + input = input. + Replace("log(", "log10(", true, CultureInfo.CurrentCulture). + Replace("ln(", "log(", true, CultureInfo.CurrentCulture); + var result = _magesEngine.Interpret(input); // This could happen for some incorrect queries, like pi(2)