Exponentiation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    Exponentiation

    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:
    Code:
    c = 1
    while b > 1 {
        c = c * a
        b = b - 1
    }
    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.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by kadghar
    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:
    Code:
    c = 1
    while b > 1 {
        c = c * a
        b = b - 1
    }
    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

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Originally posted by JosAH
      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.

      Comment

      Working...