Question

Are there known techniques for converting a loop like the following to an if and a multiplication?

while (x < 0) {
    x += 60;
}

It seems clear that this could be replaced with something like the following

if (x < 0) {
    x += f(x, 60);
}

where f contains no loops, presumably using multiplication. This would have the benefit of being faster for sufficiently large negative numbers.

Is there a well understood algorithm for finding f for an arbitrary loop of this form?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top