@altenbach wrote:
Define "better". 🙂 We are dealing with small numbers, so that loop completes in nanoseconds, basically for free. Power of x requires floating point, thus requiring two coercions (first at the function input and later wired to N) and math on twice as many bytes. Seems ugly. 🙂
Of course you also need to ensure that the loop output is correct for strange inputs. Mine is correct for 0 to the power of 0 equal 1, for example. Of course it will not work for negative powers or anything that uses or results in fractions, etc.
Better, as in performance while scaling to larger data sets, as I assume was (part of) the purpose of this exercise. The coercion ugliness I saw right away, but wasn't sure of the cost at a "large" scale, mostly because I have no idea what is going on inside that function. The inputs would need to be constrained regardless.
Not that I have much room for argument since my recursive solution would not exactly be "high performance" code at a large scale. In my defense, I knew there was an easy way to do it, if not the exact solution. I just chose recursion for fun.
(That's my excuse and I'm sticking to it.):smileyhappy: