A small collection of tools to work with rational numbers
Converts a simple mathematical expression to a continued fraction sequence
to evaluate an expression:echo "2 + 0.8031975" | expr2cf
=> [2, 1, 4, 12, 3, 4, 2, 1, 1, 1, 1, 2, 1, 1, 5]
to get an approximated fraction of pi (from 18 decimal digits):echo "scale=18; 4*a(1)" | BC_LINE_LENGTH=0 bc -l | expr2cf | cf2expr
=> 14308127635/4554418479
to get an approximated fraction of the golden ratio (Phi):echo "[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]" | cf2expr
=> 6765/4181