mage has log as ln and then has log10. (#15176)

This commit is contained in:
Clint Rutkas
2021-12-28 04:59:31 -08:00
committed by GitHub
parent 939e8db692
commit f6daf0b1f6
2 changed files with 13 additions and 3 deletions

View File

@@ -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);

View File

@@ -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)