With infinite precision, r -= Poly(temp) * den would always result in the leading term of r becoming zero. With finite precision, in some pathological case, the calculation might cause the leading term to be just a little off, so instead of obtaining 0x^3 (for example) as the leading term, we get (for example) 0.0000000003x^3. Since the leading term is not zero, the degree of r does not decrease. Perhaps this might continue in the next iteration. I'm not sure what the behavior would be if it continued.

One way to recover from the problem is to set the leading coefficient of r to 0. explicitly at the end of each iteration. That will at least ensure that the degree decreases each time so that the loop eventually terminates.