I read that the pow(double, double) function is defined in \"math.h\" but I can\'t find its declaration.
Does anybody know where this function declared? And where i
Here's a C implementation for fdlibm: http://www.netlib.org/fdlibm/e_pow.c
For what it's worth, when v8 dropped its cos/sine tables, it pulled from fdlibm's implementation to do so: https://code.google.com/p/v8/source/detail?r=22918
From the change commit comments: "Implement trigonometric functions using a fdlibm port."
Mozilla on the other hand calls the cstdlib math functions, which will have variable performance by build and system (ex: may or may not invoke the chip-level implementations of transcendental functions). While C# bytecode seems to make explicit references to chip-level functions when it can. However, "pow" is not one of those, iirc (doesn't seem to have an chip-level function) and is implemented elsewhere.
See also: https://bugzilla.mozilla.org/show_bug.cgi?id=967709
For a cos/sine discussion in the Mozilla community, comparison of Mozilla's implementation vs old v8 implementation.
See also: How is Math.Pow() implemented in .NET Framework?
Intrinsic functions are chip-level, actually implemented on the processor. (We don't necessarily need lookup tables any more.)
I’s really defined in math.h
. Have you tried including math.h
and simply using pow
? What do you mean by “can't find it”?
Quite often, an include file such as <math.h>
will include other header files that actually declare the functions you would expect to see in <math.h>
. The idea is that the program gets what it expects when it includes <math.h>
, even if the actual function definitions are in some other header file.
Finding the implementation of a standard library function such as pow()
is quite another matter. You will have to dig up the source code to your C standard runtime library and find the implementation in there.
If you are seeking how the calculation is implemented, you can find it here: http://fossies.org/dox/gcc-4.5.3/e__pow_8c_source.html The name of the function is __ieee754_pow which is called by pow function.
declared: in the include directory of your system/SDK (e.g.: /usr/include;/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include/architecture/arm/math.h)
defined (implemented):
The extern keyword in the function declaration of pow means, that it's defined somewhere else. Math functions are low-level high-performance implementations mostly done in assembly code (*.s). The assembly routines (taking the arguments/giving the parameters via registers/stack) are linked with the rest of the C library. The linking/exporting of the function/routine names is platform specific and doesn't really matter if ones goal is not dive into assembly coding.
I hope this helped, Raphael
The actual implementation of pow
may vary from compiler to compiler. Generally, math.h (or a vendor-specific file included by math.h) provides the prototype for pow
(i.e., its declaration), but the implementation is buried in some library file such as libm.a. Depending on your compiler, the actual source code for pow
or any other library function may not be available.