Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tofrac(x0) {
- let x = x0;
- let a = Math.floor(x);
- let [h, k, h1, k1] = [a, 1, 1, 0];
- while (x - a > Number.EPSILON * k * k) {
- x = 1 / (x - a);
- a = Math.floor(x);
- let [h2, k2] = [h1, k1];
- [h1, k1] = [h, k];
- h = h2 + a * h1;
- k = k2 + a * k1;
- }
- return `${h}/${k}`;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement