Libeval

Libeval provides simple means of evaluating simple arithmetic expressions.
Download

Libeval Ranking & Summary

Advertisement

  • Rating:
  • License:
  • LGPL
  • Price:
  • FREE
  • Publisher Name:
  • Jeffrey Dutky
  • Publisher web site:
  • http://members.bellatlantic.net/~dutky/libeval.html

Libeval Tags


Libeval Description

Libeval provides simple means of evaluating simple arithmetic expressions. Libeval provides simple means of evaluating simple arithmetic expressions involving literal numeric values, variables and functions using the addition (+), subtraction (-), multiplication (*), division (/), modulo division (), exponentiation (^), sign (+-), percentag (%) and grouping (()) operators.Libeval provides a means of setting and interrogating variables, defining functions and converting error codes into human readable strings. A number of predefined functions are included with libeval that wrap the existing standard C library math functions.You can evaluate an expression by calling the eval() function. eval() takes two parameters, the expression to evaluate (as a simple C string) and a reference to a double precision float in which to put the result. If eval() encounters an error it returns a non-zero value, otherwise, if everything went well, it returns zero.The error code returned by eval() can be converted into a human readable string by the eval_error() function. eval_error() takes one parameter, the error code returned by eval(),and returns a constant string describing the error.Variables can be manipulated with the eval_set_var() and eval_get_var() functions.eval_set_var() sets the named variable to the specified double precision value. eval_set_var() takes two parameters, the name of the variable to set as a simple C string, and the double precision float value to set the variable to. it returns 0 (zero) on success, non-zero on failure.eval_get_var() gets the value of the named variable. eval_get_var() takes two parameters, the name of the variable as a simple C string and a reference to a double precision float in which to store the variables value. it returns 0 (zero) on success, non-zero on failure. Functions can be defined with the eval_def_fn() function, which takes the name of the function as a simple C string, a pointer to a C function implementing the function, a pointer to a block of custom storage for use by the function and the number of arguments taken by the function. The prototype for the implementation function is: int fn(int args, double *arg, double *rv, void *data); The first two parameters (args and arg) are similar to the standard parameters to the main() function in C, the args parameter indicates how many elements are the argument list, and arg is the argument list itself. The third parameter (rv) is the return value from the function. The last parameter (data) is the custome storage block passed in when the function was defined. If you specify a positive value (including zero) as the number of arguments for a function, libeval will only all the function to be called with exactly that number of parameters. If you specify a -1 (negative one) for the number of arguments, the function can be called with any number of parameters. The following functions are predefined: abs(x) absolute value of x int(x) integer part of x round(x) round x to nearest integer trunc(x) truncate x (same as int(x)) floor(x) round x to nearest lesser integer ceil(x) round x to nearest greater integer sin(x) sine of x (radians) cos(x) cosine of x (radians) tan(x) tangent of x (radians) asin(x) arc sine of x (radians) acos(x) arc cosine of x (radians) atan(x) arc tangent of x (radians) sinh(x) hyperbolic sine of x (radians) cosh(x) hyperbolic cosine of x (radians) tanh(x) hyperbolic tangent of x (radians) asinh(x) hyperbolic arc sine of x (radians) acosh(x) hyperbolic arc cosine of x (radians) atanh(x) hyperbolic arc tangent of x (radians) deg(x) convert radians to degrees rad(x) convert degrees to radians ln(x) natural logarithm of x log(x) base 10 logarithm of x sqrt(x) square root of x exp(x) e to x power rand() random number between 0.0 and 1.0 fact(x) factorial of x (or gamma(x) if x is non-integer) sum(...) sum of the arguments min(...) minimum value in arguments max(...) maximum value in arguments avg(...) average of arguments med(...) median of arguments var(...) variance of arguments std(...) standard deviation of argumentsFinally, you can get a set of bookkeepping information about the eval_expr libray with the eval_info() function. eval_info() takes nine parmaeters: three references to integer values for the version, revision and build numbers of the current eval_expr library, and three pairs of buffer address and buffer size limit for author's name, copyright info and license info.You can use libeval by including the libeval header in your program source #include and then by linking your program against the libeval library gcc -o myprog myprog.c -levalWhat's New in This Release:· A bug in the var() function and version string construction were fixed.


Libeval Related Software