An exponentiation function for int?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven T. Hatton

    #16
    Re: An exponentiation function for int?

    JXStern wrote:
    [color=blue]
    > On Wed, 13 Oct 2004 11:38:45 -0400, "Steven T. Hatton"
    > <susudata@setid ava.kushan.aa> wrote:[color=green]
    >>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 isn't such a function.[/color]
    >
    > Are you pressed for execution speed of this function?
    >
    > J.[/color]
    I've already far surpassed what my immediate needs are. But the exercise of
    trying to optimize an unsigned int exponentiation function has paid off in
    a big way. I really had no intention of getting into this problem so
    deeply. But since it was interesting, and it allowed me to explore many
    aspects of template metaprogramming , I pursued it.

    As for why I originally wanted the function, I simply don't like using type
    conversions that are potentially lossy, nor do I like casting with anything
    but a dynamic cast. I was working with unsigned int - size_t to be more
    specific. I didn't like the idea of converting back and forth between
    integer and floating point representations .

    I've discovered that I can store all my calculations in a single static base
    class, and reuse the results, so speed of an int power function has become
    nothing more than an academic exercise at this point.

    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell

    Comment

    Working...