pow() question

D

david.corby

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::power, but I'm
trying to keep my code portable.

Thanks in advance,
Dave
 
J

John Harrison

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::power, but I'm
trying to keep my code portable.

Really how hard would it be to write your own function? You could even pinch
the code from __gnu_cxx::power, 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
 
D

david.corby

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top