A Powerful Function Parser

.

The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like

"cos(x)-7*x/(1+x)"
and you want to compute some values, maybe for displaying the graph of the function. You can write code like this:

CFunction<long double>* fkt = 
  CFunction<long double>::Parse("cos(x)-7*x/(1+x)");

long double y = fkt->Execute(1.5);

There are lots of definitions in the background, but the result is easy and fast! There is a one-time pasing step to construct the function tree, and function evaluations are only calls of standard math functions like sin, +, *, sqrt. When you want to know details about the implementaion, you should look into the source code. It would be too complex to describe the parsing algorithm here.

Downloads

Download demo source - 50 Kb
Download demo application - 32 Kb


Comments

  • Can I Take Shilajit Capsules To Cure Erectile Dysfunction?

    Posted by afoeffifielm on 06/21/2013 02:12am

    Natural Impotence Cure- Naturally Curing Your Erectile Dysfunction Can Help To Conserve Your Life? If you opt for discretion, you can fill the prescription at a reliable on-line pharmacy [url=http://rxhealth.pw ] countries where you can buy viagra over the counter [/url] see far more Lifelike Cures for Erectile Dysfunction Explained

    Reply
  • Just OK

    Posted by Legacy on 01/14/2004 12:00am

    Originally posted by: Gerhalt

    very ok!

    Reply
  • Very good, but ...

    Posted by Legacy on 10/16/2003 12:00am

    Originally posted by: Alexander Magola

    My english is not good, but i want to say that this code is very good. I like idea of this author, but this code is not very fast. My own similar code is faster three times more than it. Although, my code is not fastest. ;)
    Best regards.

    Reply
  • How about adding new functions to this as plug-ins

    Posted by Legacy on 07/03/2003 12:00am

    Originally posted by: Harshdeep Singh

    Great Job
    I was thinking about giving option of adding new functions as plug-ins (dll?)
    That would make it cooler.
    And I would love to see an explanation of the code.
    Harshdeep

    Reply
  • Vergleich Fl�chenberechnungen

    Posted by Legacy on 03/15/2003 12:00am

    Originally posted by: Oswald Ruckriegel

    Zun�chst: ein Spitzenprogramm. Meine Gratulation
    Habe es in mein Programm (VC++5.0) eingebaut.
    Stelle fest: am genauesten rechnet
    1. Mittelpunktsregel
    2. Integration mit Trapezregel
    3. Simpson ( hier Abweichungen von 1) bis zu 10 %.
    Beispiel: sin(x)/x ( f�r x= 0 bis x = 3)
    nur 1) berechnet richtig, 2) und 3) keine Berechnung m�glich.

    Warum ?

    Reply
  • The console app closes immediately

    Posted by Legacy on 11/13/2002 12:00am

    Originally posted by: The Big Cat

    Hi there may not be a bug in the program but when i type the
    
    f(x)=_ in the console demo application then
    when i enter x and then press enter the console application closes .
    how am i to verify the results?Maybe the code should be
    modified to ask another f(x) at the end so the window wouldn't close and the user can test another function.
    You could just put in a prompt ,say 'Quit Y?N ?'..
    Otherwise good ,i've gotto see the code..

    Reply
  • Error using sqrt

    Posted by Legacy on 09/04/2002 12:00am

    Originally posted by: Holger

    There is an error in the GetDerivate() Method of the class CSqrt1Function. The "1/2" expression becomes 0. For correct behaviour replace it with "1.0/2.0" or with "0.5" (see code below).
    
    

    Thanks for this great piece of code.

    Regards, Holger.


    template <class T>
    class CSqrt1Function : public CFunction<T>
    {
    ...
    virtual CFunction<T>* GetDerivate() const {return new CDivL0Function<T>(1/2, new CSqrt1Function<T>);};
    };

    Reply
  • Found an error

    Posted by Legacy on 08/20/2002 12:00am

    Originally posted by: Lee


    The expression: x^2+3x-5

    was parsed to: x^2+3-5

    Reply
  • few

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: few

    So fucking cool thing!

    Reply
  • A Powerful Function Parser

    Posted by Legacy on 04/10/2002 12:00am

    Originally posted by: Nikhil

    Impressive....but comments are not clear
    and extensive....Comments in English would be a definite help!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Hundreds of millions of users have adopted public cloud storage solutions to satisfy their Private Online File Sharing and Collaboration (OFS) needs. With new headlines on cloud privacy issues appearing almost daily, the need to explore private alternatives has never been stronger. Join ESG Senior Analyst Terri McClure and Connected Data in this on-demand webinar to take a look at the business drivers behind OFS adoption, how organizations can benefit from on-premise deployments, and emerging private OFS …

Most Popular Programming Stories

More for Developers

RSS Feeds