Calculates the continued fraction expansion of a number