473,388 Members | 1,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Exponentiation

kadghar
1,295 Expert 1GB
Hello Experts:

I was wondering if anyone knows how does a computer do exponents operations (powers).

I know its simple when the exponent is a positive integer.
a^b can be easily done with:
Expand|Select|Wrap|Line Numbers
  1. c = 1
  2. while b > 1 {
  3.     c = c * a
  4.     b = b - 1
  5. }
  6. return c
But what about the ones that work when exponent is a real number, like:

4^1.45 = 7.464263932

Any help will be greatly appreciated.

Kad.
Apr 1 '08 #1
2 1213
JosAH
11,448 Expert 8TB
Hello Experts:

I was wondering if anyone knows how does a computer do exponents operations (powers).

I know its simple when the exponent is a positive integer.
a^b can be easily done with:
Expand|Select|Wrap|Line Numbers
  1. c = 1
  2. while b > 1 {
  3.     c = c * a
  4.     b = b - 1
  5. }
  6. return c
But what about the ones that work when exponent is a real number, like:

4^1.45 = 7.464263932

Any help will be greatly appreciated.

Kad.
For general exponentiation the so called 'CORDIC' algorithms are used. Google
knows about it but you really have to look for them (they're patented). For b
being a positive integer a 'divide and conquor' method would be much better:
a^b == a^(b/2)*a^(b-b/2) where '/' is the integer division operator.

kind regards,

Jos
Apr 2 '08 #2
kadghar
1,295 Expert 1GB
For general exponentiation the so called 'CORDIC' algorithms are used. Google
knows about it but you really have to look for them (they're patented). For b
being a positive integer a 'divide and conquor' method would be much better:
a^b == a^(b/2)*a^(b-b/2) where '/' is the integer division operator.

kind regards,

Jos
Yeah, yeah, now lets discuss about 'b' as the positive integer, thats for sissy girls. Show me your real exponents!!.

Ha!, positive integers... ...listening a Chess match on the radio seems more fun to me.

Anyway, thanks Jos, things i've found about CORDIC have been of great help in what i'm doing. I'll share some of it later, in an article.
Apr 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeff Davis | last post by:
I was doing some thinking about exponentiation algorithms along with a friend, and I happened upon some interesting results. Particularly, I was able to outperform the ** operator in at least one...
15
by: Steven T. Hatton | last post by:
Did I mess something along the way, or is there no function in Standard C++ to raise an (unsigned) int to a power of (unsigned) int returning (unsigned) int? I never gave this a second thought...
5
by: PeteCresswell | last post by:
----------------------------------------------------------------- Sub Sheesh() Dim myYears As Double Dim myRawCumulative As Double Dim myAnnualizedROR As Double ...
2
by: David Laub | last post by:
I know there is no C# exponentiation operator. But since the double class is sealed, there seems no way to add the operator override without creating a new class which uses containment (of a...
3
by: James McGivney | last post by:
What is happening here ? long longg = 5; longg = longg + (2 ^ 8); the answer should be 5 + 256 or 261 but at the end of the above operation C# returns longg = 5 + 10 or 15
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
7
by: elventear | last post by:
Hi, I am the in the need to do some numerical calculations that involve real numbers that are larger than what the native float can handle. I've tried to use Decimal, but I've found one main...
8
by: grahamhow424 | last post by:
Hi I am trying to figure out how to duplicate a, financial, calculation that uses the caret, Exponentiation. Here's the formula... A = 0.0755 B = 34 C = 50000
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.