by pbsd · 11y ago · 0 comments
int x2(int x) { return x + x; }
int x4(int x) { return x2(x) + x2(x); }
int x8(int x) { return x4(x) + x4(x); }
int x16(int x) { return x8(x) + x8(x); }
int x32(int x) { return x16(x) + x16(x); }Maybe I don't understand what the word recursion means, but I thought that you'd have to call yourself directly or indirectly.
You could state it that the multiple by a power of two is the sum of the multiples of one order of magnitude base 2 lower.
By these definitions, all but the most trivial code is recursive.
// e is a power of two
int mult(x, e)
return e==1 ? x : mult(x, e/2) + mult(x, e/2)
end