Skip to content

zhengxyz123/num2expr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

num2expr

num2expr is a header-only C library to convert a floating-point number into some specific mathematical expressions.

A very fast guide:

#define NUM2EXPR_IMPLEMENTATION
#define NUM2EXPR_NEED_PRINT_FUNCTION
#include "num2expr.h"

int main(void) {
    num2expr_expr* expr = num2expr(2 * M_PI / 3);
    // will print "((2*pi)/3)"
    num2expr_print_expr(expr);
    printf("\n");
    num2expr_free_expr(expr);
    return 0;
}

It supports the following formats:

  1. $\frac{a}{b}$
  2. $\frac{\sqrt{a}}{b}$
  3. $\frac{\sqrt{a}+\sqrt{b}}{c}$
  4. $\text{some value}\times\pi$

We use a new algorithm to calculate the (3) format, You can find more information about the algorithm in this blog.

All codes were also written in Python (but with no expression tree).

About

Converting floating point numbers into mathematical expressions like sqrt(a)±sqrt(b)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors