Calculator icon indicating copy to clipboard operation
Calculator copied to clipboard

Shouldn't this work?

Open gap777 opened this issue 8 years ago • 5 comments

Wrapping an expression in parenthesis seems to cause what otherwise is valid to be invalid:

(3 + Pow(2, 3))

In MathEvaluator.TryComma(), _nestedFunctionDepth (which is 1) < _nestedGroupDepth (which is 2).

What's the purpose of that particular assertion/check? What is it trying to guard against?

Can you think of a code change to support this expression?

gap777 avatar Jun 30 '16 21:06 gap777

3+(2^3)

pwelter34 avatar Jul 01 '16 14:07 pwelter34

Paul, I'm trying to communicate that the library fails to parse things when the superfluous enclosing parenthesis around the whole expression are included.

gap777 avatar Jul 01 '16 14:07 gap777

that code is making a poor assumption that a function would only take 1 param. I've been meaning to fix that, want to support things like round(123.456, 2)

pwelter34 avatar Jul 01 '16 14:07 pwelter34

I just added the "round" function on my fork.

It mostly works fine, except for the case I've raised to your attention.

On Fri, Jul 1, 2016 at 10:50 AM, Paul Welter [email protected] wrote:

that code is making a poor assumption that a function would only take 1 param. I've been meaning to fix that, want to support things like round(123.456, 2)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/loresoft/Calculator/issues/4#issuecomment-229966953, or mute the thread https://github.com/notifications/unsubscribe/AGMdeuktd8n4Ni3Le4MHBcu0ZD8OSnxVks5qRSkkgaJpZM4JCmBG .

gap777 avatar Jul 01 '16 14:07 gap777

Round fails at the moment because the "TwoArgumentFunction" section of code uses reflection to find methods on the Math class with signatures that take (Double, Double).

Math.Round takes (Double, Int) causing the reflection: typeof(Math).GetMethod(....... to return null.

I couldn't come up with anything more elegant than if (_function == "Round") then changing the desiredMethodSignatureArgs from Double,Double to Double,Int. This fixes the reflection to find the Math.Round function but then you still have two doubles to pass to it, so it doesn't work ... yet!

clumsybiker avatar Oct 26 '16 07:10 clumsybiker