Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. function tofrac(x0) {
  2. let x = x0;
  3. let a = Math.floor(x);
  4. let [h, k, h1, k1] = [a, 1, 1, 0];
  5.  
  6. while (x - a > Number.EPSILON * k * k) {
  7. x = 1 / (x - a);
  8. a = Math.floor(x);
  9. let [h2, k2] = [h1, k1];
  10. [h1, k1] = [h, k];
  11. h = h2 + a * h1;
  12. k = k2 + a * k1;
  13. }
  14.  
  15. return `${h}/${k}`;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement