pow() question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • david.corby@gmail.com

    #1

    pow() question

    I would like to know a few things about the pow() function.

    1.) Is it an efficient way to raise a number to a given power for both
    small and large numbers?
    2.) How accurate is pow() when doing integer calculations? I'm
    basically just going to use it to get powers of 10, but I can't have
    pow(10, 6) == 999999 or 1000001 when I bring it back to an integer.
    3.) Is there an integer-only version of pow in the STL that I'm missing
    somewhere? I've found SGI's extension, and __gnu_cxx::powe r, but I'm
    trying to keep my code portable.

    Thanks in advance,
    Dave

  • John Harrison

    #2
    Re: pow() question


    <david.corby@gm ail.com> wrote in message
    news:1098396719 .387874.255870@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    >I would like to know a few things about the pow() function.
    >
    > 1.) Is it an efficient way to raise a number to a given power for both
    > small and large numbers?
    > 2.) How accurate is pow() when doing integer calculations? I'm
    > basically just going to use it to get powers of 10, but I can't have
    > pow(10, 6) == 999999 or 1000001 when I bring it back to an integer.
    > 3.) Is there an integer-only version of pow in the STL that I'm missing
    > somewhere? I've found SGI's extension, and __gnu_cxx::powe r, but I'm
    > trying to keep my code portable.
    >[/color]

    Really how hard would it be to write your own function? You could even pinch
    the code from __gnu_cxx::powe r, provided you give them credit I'm sure they
    wouldn't mind.

    I think the answer to questions 1 and 2 is implementation dependent. Which
    is why if you have particular requirements you should code it yourself. The
    answer to question 3 is no.

    john


    Comment

    • david.corby@gmail.com

      #3
      Re: pow() question

      Ah, I see. Well, coding my own function isn't a problem, but I was
      looking for the STL to define a function so that I could take advantage
      of it requiring certain results while leaving the implementors free to
      use the best architecture-dependant method they could. Thanks though,
      now I can stop looking and take the 3 minutes it'll take to write :P

      Comment

      Working...