I'm struggling to add a new function (nCr) to DDMathParser. I've tried to follow these instructions by the author of DDMathParser:
https://stackoverflow.com/a/15599814/2521277
My problem: I can't manage to combine DDExpressions to a complex expression with variables...
Can you help me to add the function nCr (http://en.wikipedia.org/wiki/Binomial_coefficient#Factorial_formula)
Thank you!
DDMathParser author here.
The basic signature for all functions is this:
So you need to create one of these blocks that implements the nCr algorithm. There are a couple of ways you could do it:
Personally, I'd recommend the last one, because it saves having to re-evaluate the arguments, but also means you don't have to write most of the logic yourself.
It'd be something like this:
With this block, you can register the function on your
DDMathEvaluator
:That's it!
Now you can do:
Warning: code typed in a browser and not compiled. Caveat Implementor
Incidentally, if this is a function you'd like to see built-in to DDMathParser, please open a new issue over at Github.