works for all rational numbers not just integers