473,411 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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

Thanks in advance,
Dave

Jul 22 '05 #1
2 1614

<da*********@gmail.com> wrote in message
news:10**********************@z14g2000cwz.googlegr oups.com...
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
Jul 22 '05 #2
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

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Magix | last post by:
#include <math.h> double pow( double base, double exp ); will pow (2, -30) works fine ? (exp is negative value). If not, what are the workaround for exp to be negative?
13
by: Shaobo Hou | last post by:
Can anyone tell me why pow(-8.0, 1.0 / 3.0) (cubic root of -8) returns nan (in linux) and negative infinity or something (in devcpp in windows), instead of -2? The problem seems to be that pow...
52
by: Michel Rouzic | last post by:
I obtain an unwanted behavior from the pow() function : when performing pow(2, 0.5), i obtain 1.414214 when performing pow(2, 1/2), i obtain 1.000000 when performing a=0.5; pow(2, a), i obtain...
11
by: Russ | last post by:
I have a couple of questions for the number crunchers out there: Does "pow(x,2)" simply square x, or does it first compute logarithms (as would be necessary if the exponent were not an integer)?...
15
by: Mark Healey | last post by:
I'm using gcc on a fedora 3 system here are what I think the relevant lines are: #include <math.h> r=pow(2,z); When I compile I get
42
by: John Smith | last post by:
In a C program I need to do exponentiation where the base is negative and the exponent is a fraction. In standard C this would be something like t = pow(-11.5, .333), but with this combination of...
13
by: siggi | last post by:
Hi all, this is a newbie question on : Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32 PC with WinXP In http://www.python.org/doc/2.3.5/lib/module-math.html I read:
0
by: richyjsm | last post by:
it's a serious question: why does the builtin pow function exist? for two argument pow we've got **. there's no add() for + or mul() for *.... and three argument pow-with-modulo seems like...
18
by: Peng Yu | last post by:
Hi, I'm wondering if there is any general guideline on when to using something like std::pow(x, n) rather than x * x * x * ... * x (n x's). Thanks, Peng
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.