473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exponentiation

kadghar
1,295 Recognized Expert Top Contributor
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 1230
JosAH
11,448 Recognized Expert MVP
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 Recognized Expert Top Contributor
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
1412
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 case, with a recursive algorithm. This leads me to believe that perhaps the ** operator should tune it's algorithm based on inputs or some such thing. Here is my data: >>> def h(b,e): .... if(e==0): return 1 .... if(e==1): return b
15
11656
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 until today. I tried to do it, and discovered <cmath> std::pow() only takes floating point types for the first argument. Sure I could write one. I could have written at least 3 fundamentally differnet versions in the time it took to discover there...
5
3465
by: PeteCresswell | last post by:
----------------------------------------------------------------- Sub Sheesh() Dim myYears As Double Dim myRawCumulative As Double Dim myAnnualizedROR As Double myYears = 1.25 myRawCumulative = -9.24161581346505 myAnnualizedROR = ((myRawCumulative ^ (1 / myYears)) - 1)
2
4586
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 double value) This seems a major pain, and would probably wind up being more syntactically messy than just calling Math.Pow(x,y) Surely greater minds than I have already wrestled with this problem...
3
7875
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
8661
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 in low-level numerical computations, replacing Fortran in newer projects. Check, for example, sourceforge.net or freshmeat.net But neither language offers a primitive exp operator.
7
2354
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 obstacle that I don't know how to sort. I need to do exponentiation with real exponents, but it seems that Decimal does not support non integer exponents.
8
5670
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
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.