Skip to content

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

License

Notifications You must be signed in to change notification settings

zhengxyz123/num2str

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

num2str

num2str is a tiny Python library to convert a floating number into some specific mathematical expressions. The algorithm, which can be used in numerical calculation tools, is simple and efficient.

The following example shows how to use this library:

>>> from math import *
>>> from num2str import num2str
>>> num2str(3 / 5)
'3/5'
>>> num2str(pi / 2)
'π/2'
>>> num2str(-2 * sqrt(3))
'-2sqrt(3)'
>>> num2str(sqrt(2) + sqrt(3))
'sqrt(2)+sqrt(3)'

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.

We have also rewritten all the Python code using C (in progress). You can copy num2str.c and num2str.h into your own project.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published