Convert decimals to approximate rational expressions
You come across the number 0.866025. It looks vaguely familiar but you can’t quite point your finger at it? Then dedec is for you.
dedec is a small command-line utility that “de-decimalizes” decimal numbers into approximate rational expressions (with some basic functions).
$ dedec 0.4285714285 3 / 7 -7.1429e-11 sqrt(9 / 49) -7.1429e-11
$ dedec 0.866025 sqrt(3 / 4) -4.0378e-07 sin(1 / 3 * pi) -4.0378e-07 cos(1 / 6 * pi) -4.0378e-07
It can also be used from Python
import dedec a = 3.0 / 7.0 sols = dedec.dedec(a) numerator, denominator, mult_pi, fun, diff = sols assert numerator == 3 assert denominator == 7
dedec is available from the Python Package Index, so simply type
pip install -U dedec
to install or upgrade.
Download dedec from GitHub and install it with
python setup.py install
To run the dedec unit tests, check out this repository and type
To create a new release
bump the __version__ number,
publish to PyPi and GitHub:
$ make publish
dedec is published under the MIT license.