Created
January 18, 2013 23:15
-
-
Save anonymous/4569504 to your computer and use it in GitHub Desktop.
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ function float2rat(x) { tolerance = 1.e-4; h1=1; h2=0; k1=0; k2=1; b = x; do { a = Math.floor(b); aux = h1; h1 = a*h1+h2; h2 = aux; aux = k1; k1 = a*k1+k2; k2 = aux; b = 1/(b-a); } while (Math.abs(x-h1/k1) > x*tolerance); return h1+"/"+k1; }