The previous code seemed to be assuming that the rational exponent a/b satisfied 0 <= a < 2*b, but of course this does not have to be true. I also removed the code that separated the 0 <= a <= b and b < a < 2b cases because I didn't see the reason for the difference. The output seems to always be the desired outcome with this new simplified code.
The previous code seemed to be assuming that the rational exponent a/b satisfied 0 <= a < 2*b, but of course this does not have to be true. I also removed the code that separated the 0 <= a <= b and b < a < 2b cases because I didn't see the reason for the difference. The output seems to always be the desired outcome with this new simplified code.