CodePlea icon
Random thoughts on programming
21 Jan 2016

Math Expression Parsing in C

I published some code over at Github today. It's a tiny library called TinyExpr. It parses, compiles, and evaluates math expressions.

    #include "tinyexpr.h"
    #include <stdio.h>

    int main(int argc, char *argv[])
        const char *expression = "sqrt(5^2+7^2+11^2+(8-2)^2)";
        printf("Result: %f\n", te_interp(expression, 0));
        return 0;

Anyway, it's quite fast, and it has other features like variable binding. It's all implemented in one ANSI C source file with no dependencies. Check it out!

Like this post? Consider following me on Twitter or following me on Github. Don't forget to subscribe to my feed.