Intel's Ronler Acres Plant

Silicon Forest

Friday, March 25, 2016

Simple Wikipedia

Exponentiation by Squaring
I monkeying around with the Go programming language and I need to raise number 10 to a low power like 1, 2 or 3. That's easy enough, but is there some library function already written that will do that? I mean part of learning a new programming language is learning what's in all the various libraries. So I go looking around and the general attitude seems to be that this is so simple you may as well write it yourself, unless you want to use the floating point routine, which is fine except you incur the extra overhead of floating point numbers.

But then somebody points out that Wikipedia has an article titled Exponentiation by Squaring which is a dozen or so screens of mathematical gibberish, and the somebody else points out that there is the Simple Wikipedia which also has an article on the same subject and it is only one screenful. I like Simple Wikipedia. I use Wikipedia all the time. Mostly it doesn't give me any trouble, but sometimes it gets really deep, and sometimes that is too deep for me.

The technique is overkill for my problem, so I will just roll my own.

1 comment:

Ole Phat Stu said...

It is also wrong.
Or rather, incomplete.
The case for n=0 (i.e returning 1) is not covered.
Nor can it cope with negative or imaginary numbers for n.