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

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

  • Ever-increasing workloads and the challenge of containing costs leave companies conflicted by the need for increased processing capacity while limiting physical expansion. Migration to HP's new generation of increased-density rack-and-blade servers can address growing demands for compute capacity while reducing costly sprawl. Sponsored by: HP and Intel® Xeon® processors Intel, the Intel logo, and Xeon Inside are trademarks of Intel Corporation in the U.S. and/or other countries. HP is the sponsor …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds