Re: calculating an exponent?
From: Alf P. Steinbach (alfps_at_start.no)
Date: 09/28/04
- Next message: Justin Nahin: "Make money with your programming skills!!"
- Previous message: Jani Yusef: "calculating an exponent?"
- In reply to: Jani Yusef: "calculating an exponent?"
- Next in thread: Jani Yusef: "Re: calculating an exponent?"
- Reply: Jani Yusef: "Re: calculating an exponent?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Sep 2004 06:29:54 GMT
* Jani Yusef:
> Ok, this one has me stumped.
> Is it possible to calculate an exponent, say, a^n, using only right
> and left shifts along with additions and subtractions?
All arithmetic operations are implemented that way (in software or hardware).
Presumably 'a' and 'n' are non-negative integers.
The only question is then how (in)efficient you want the algorithm to
be. For efficiency it might be a good idea to first consider efficient
multiplication. With multiplication you can then tackle the efficiency of the
exponentiation, e.g. by noting treating odd n and even n differently.
-- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
- Next message: Justin Nahin: "Make money with your programming skills!!"
- Previous message: Jani Yusef: "calculating an exponent?"
- In reply to: Jani Yusef: "calculating an exponent?"
- Next in thread: Jani Yusef: "Re: calculating an exponent?"
- Reply: Jani Yusef: "Re: calculating an exponent?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|