![]() |
|
#1
|
|||
|
|||
Contents or source for pow() functionhiiiii,
How can I open library in c++? And How can I see functions in c++? for example : I want see (pow(x,y) function). I have visual c++. I want open it by this program. |
|||
|
#2
|
|||
|
|||
Re: How?Quote:
First, RTFG.... Second: #include <cmath> :davis: |
|
#3
|
|||
|
|||
|
What dose mean ((RTFG....))?
|
|
#5
|
|||
|
|||
Re: How?Quote:
If you want to use the function, then #include <cmath>, as Davis suggested. If you want to look at the source code for pow(), you should know that this is not supplied by Microsoft for their library functions. (Same for Borland.) For GNU compiler installations, it is possible to look up the source code for everything, but there are some issues: 1. It is very likely that such things will include some very low level asm or other low-level bit manipulations and/or platform-specific floating point instructions to ensure the efficiency and robustness required for library functions, so if you are looking to learn "good programming practices", GNU source may not be the way to start. (Man, oh, man; look at all of those "goto" statements!!!) 2. It's kind of hard to find. Start at www.gnu.org and poke around; you might find library source code somehow, somewhere. For example with the C++ in the GNU compiler suite, there are several pow() functions prototyped in <cmath>: CPP / C++ / C Code:
The fun part: All are #defined to use built-in functions, whose actual code is buried (waaaaay deeply) in the source code --- somewhere. If, for learning purposes, you want to make your own pow() function, then you can start with the mathematical definition of what "x to the power y" really means: "x to the power y" in general is defined as "exp(y log x)". Where exp() is the exponential function, and log means natural log (log to the base e, where e = exp(1)). Note that a special case for negative numbers raised to integer powers is needed, since the above definition would be meaningless (log of a negative number is undefined), but such expressions are commonly used in lots of places. That is, "something" raised to the "n" power is (loosely) defined as "something" multiplied by itself with a total of "n" factors, so, for example pow(-2.0, 3) gives -8.0 Note that the "something" multiplied by itself "n" times definition only works for powers that are ints, since it couldn't be used for something like "3.4 raised to the 5.6 power". Also: how would you handle something like "zero raised to the -3 power"? You can try different values of x and n in the following: CPP / C++ / C Code:
You should see something like: Code:
(Check it with a calculator, if you want to.) Regards, Dave |
|
#6
|
|||
|
|||
Re: How?Quote:
I think that you will find the sources to the Microsoft implementation of their standard C library--since MS VS6--in the header files implemented as inline functions. See the contents of math.h for more information. :davis: |
|
#7
|
|||
|
|||
Re: How?Quote:
I didn't realize that (and, of course, it's not the first time that I have been wrong --- not even the first time this year). For floats, doubles, long doubles raised to int powers there is a template function fully defined in <math.h> The other pow() functions (things raised to floating point powers) aren't as easy to find (at least I don't see them). Thanks for the info. Regards, Dave |
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The