ncalc icon indicating copy to clipboard operation
ncalc copied to clipboard

Units

Open shockfield opened this issue 1 year ago • 5 comments

Hello,

i was just wondering if it is already in some way possible to calculate expressions with units using NCALC, or if it could theoretically be implemented in the future:

For example: 10mm + 10mm = 20mm 10mm + 10N : Failed evaluation 10mm * 10N = 100 Nmm 10N / 10mm = 1 N mm^-1 10mm * 10mm = 100 mm^2 10mm + 1m = 1010mm

Greetings, Simon

shockfield avatar May 12 '24 12:05 shockfield

Good morning Simon!

Next week I'm going to start to work on #137. I will evaluate if this is possible with Parlot or we would need some event handling (probably the way at this version).

gumbarros avatar May 12 '24 12:05 gumbarros

Great. If your evalution turns out optimistic and you are open to it, don't hesitate to get in touch to see if I there is something I could do to help.

ghost avatar May 12 '24 13:05 ghost

@shockfield I'm thinking in your problem, I think this is not possible at Parlot, is more an evaluation problem and not a parsing problem.

I think you can create your custom logic using OnEvaluateParameter and [] around the numbers and check the unit at the end of the variable name. Feel free to send questions or more ideas.

gumbarros avatar May 22 '24 01:05 gumbarros

@gumbarros , hi can you show me an example of what you mean? something like this?

e.EvaluateParameter += delegate(string name, ParameterArgs args) { if (name.EndsWith("mm")) Unit = "mm" ..? };

From your documentation:

e.Parameters["Pi2"] = new Expression("Pi * [Pi]");

What is the difference between Pi and [Pi] here? What purpose do the [] serve?

ghost avatar May 22 '24 13:05 ghost

e.EvaluateParameter += delegate(string name, ParameterArgs args) { if (name.EndsWith("mm")) Unit = "mm" ..? };

Yes this is my idea.

What is the difference between Pi and [Pi] here? What purpose do the [] serve?

Nothing. [] is to prevent conflicts with other things in the parser, like [not] is a variable and not is a unary operator. [Pi] and Pi have no difference.

gumbarros avatar May 22 '24 13:05 gumbarros

@shockfield, fill free to close the issue if it is resolved

Bykiev avatar Nov 03 '24 09:11 Bykiev

Closed due inactivity.

gumbarros avatar Nov 17 '24 00:11 gumbarros