Closed redfast00 closed 1 week ago
Hi redfast,
thanks for your interest in the app! Yes, the "to" handling is a bit weird. The "to" expressions are only automatically handled by the calculator.calculate
function with its input argument being a string. All other functions (like calculator.parse
) do not properly recognize the "to" keyword. I can imagine that the MathStructure object can not represent the to expressions natively? As far as I could see, the qalculate-cli and qalculate-gtk project manually add code to recognize the "to" keyword and handle the conversion in a large case structure.
I will need to ask the upstream Qalculate developers to shed some light on this. @hanna-kn, if you have time, can you maybe shed some light on the "to" keyword and conversion handling?
The "to" keyword affects how the result is presented. The keyword is not represented in MathStructure and is not supported by Calculator::parse() (and neither is "where"). The simplest solution is to use Calculator::separateToExpression() (and Calculator::separateWhereExpression()).
For unit conversion, and other conversions supported directly by Calculator::calculate() (with string input), the expression after "to" can however be represented by MathStructure, and can optionally be returned by Calculator::calculate() (in the MathStructure *to_struct argument which is used both as an output and an input argument).
Calculator::calculateAndPrint() (and the newly introduced Calculator::parseToExpression()) and the user interfaces supports additional "to" conversions, such as number base conversion, primarily affecting the output from MathStructure::print(). These can not be represented by MathStructure.
Fixed in 0a76e8750a2ef7ed12ed1f820d2ae4180c25d4fb
I'm using the pre-release v1 right now. When I type in
10 miles to km
, it parses as10 mi t B km
, but shows the correct result.Aside: thanks for making the release available; I'm looking forwards to installing via F-Droid as well :)