JSFiddle - React, Tailwind, and code Playground

CoffeeScript

f=(a,b,x=0,y=1,p=0)->a&&f(b%a,a,(x+p<<b/a)-p,y<<b/a,1-p)||[x+p,y]

console.log(f(2,3));
console.log(f(4,7));
console.log(f(1,1));