Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4055112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:39:37+00:00 2026-05-20T14:39:37+00:00

Is there any free library to let a user easily build a C mathematical

  • 0

Is there any free library to let a user easily build a C mathematical expression, which can be used like any other function? I mean c expression/function which could be as quick as ‘inline’ mathematical expression and could be used many times in program.
I think I can be done in C somehow, but does anybody can tell if it could be real if it have to be a CUDA dveice function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:39:37+00:00Added an answer on May 20, 2026 at 2:39 pm

    There are a few options. I assume you want something that the user can “call” several times, like this:

    void *s = make_func("2 * x + 7");
    ...
    printf("%lf\n", call_func(s, 3.0)); // prints 13
    ...
    printf("%lf\n", call_func(s, 5.0)); // prints 17
    ...
    free_func(s);
    

    One option is to implement this as a recursive structure holding function pointers and constants. Something like:

    enum item_type { VAR, CONST, FUNC };
    
    struct var {
      enum item_type;
      int id;
    };
    
    struct constant {
      enum item_type;
      double value;
    };
    
    struct func {
      enum item_type;
      double (*func)(double, double);
      enum item_type *a, *b;
    };
    

    Then make_func would parse the above string into something like:

    (struct func *){ FUNC, &plus,
      (struct func *){ FUNC, &times,
        (struct constant *){ CONST, 2 },
        (struct var *){ VAR, 'x' } }
      (struct constant *){ CONST, 7 } }
    

    If you can understand that – the enum type_item in the struct func is used to point to the next node in the tree (or rather, the first element of that node, which is the enum), and the enum is what our code uses to find out what the item type is. Then, when we use the call(void *, ...) function, it counts how many variables there are – this is how many extra arguments the call function should have been passed – then replaces the variables with the values we’ve called it with, then does the calculations.

    The other option (which will probably be considerably faster and easier to extend) is to use something like libjit to do most of that work for you. I’ve never used it, but a JIT compiler gives you some basic building blocks (like add, multiply, etc. “instructions”) that you can string together as you need them, and it compiles them down to actual assembly code (so no going through a constructed syntax tree calling function pointers like we had to before) so that when you call it it’s as fast and dynamic as possible.

    I don’t know libjit’s API, but it looks easily capable of doing what you seem to need. The make_func and free_func could all be pretty much the same as they are above (you might have to alter your calls to call_func) and would basically construct, use, and destroy a JIT object based on how it parses the user’s string. The same as above, really, but you wouldn’t need to define the syntax tree, data types, etc. yourself.

    Hope that is somewhat helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any free java library which I can use to convert string in
Are there any free tools that implement evidence-based scheduling like Joel talks about ?
Is there any free open source chart library available for iphone/ipad ?
Is there any open-source or free chart library for Qt? I only need XY
Is there any free or commercial component written in .NET (no COM interop) that
Is there any free hosting for Javascript? Recently google has been hosting jQuery,etc... and
Is there any free tool available for creating and editing PNG Images?
Is there any free software tool or combination that allows me to identify the
Are there any free tools for scripting MSSQL table data? I'll gladly write one,
Is there any free set of forms, icons, styles, images, etc for building web-based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.