Where is the pow function defined and implemented in C?

I read that the pow (double, double) function is defined in "math.h", but I cannot find its declaration.

Does anyone know where this function is declared? And where is it implemented in C?

Link:

http://publications.gbdirect.co.uk/c_book/chapter9/maths_functions.html

+3
c function declare pow
source share
8 answers

A quite often included file, such as <math.h> , will contain other header files that actually declare functions that you 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 an implementation of a standard library function such as pow() is a completely different matter. You will have to dig the source code into your standard C runtime library and find the implementation there.

+9
source share

Where it is determined depends on your environment. The code is inside the compiled C standard library.

Its "definition" is in the source code for your standard library distribution. One such distribution is eglibc. This can be viewed on the Internet or in the source distribution:

w_pow.c

math_private.h

Short answer: in the source code of the standard C library.

+4
source share

declared: in your systemโ€™s include directory / SDK (for example: / usr / include; /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include / architecture / leverage / math.h)

defined (implemented):

  • as a library (compiled, binary): in the library directory of your system / SDK (for example: / usr / lib (in the case of a mathematical library, it is libm.dylib)
  • as a source (program code): this is the interesting part. I am currently working on Mac OS X 10.6.x. Sources for functions declared in math.h (for example: extern double pow (double, double);) do not come with the installation (at least I could not find it). You will probably find these sources in your system / SDK C library. In my case, the math library (libm) is a separate project, some of its sources are provided by Apple: http://www.opensource.apple.com/tarballs/Libm/Libm-315.tar.gz

The extern keyword in a pow function declaration means that it is defined elsewhere. Mathematical functions are low-level, high-performance implementations that are mostly executed in assembly code (* .s). Assembly procedures (taking arguments / setting parameters through registers / stack) are connected with the rest of the C library. Linking / exporting function / subroutine names is platform dependent and does not matter much if one target is not immersed in the assembly.

Hope this helps, Raphael

+3
source share

The actual implementation of pow may vary from compiler to compiler. Typically, math.h (or the vendor-specific file included in math.h) provides a prototype for pow (i.e., its declaration), but the implementation is similar to 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.

+2
source share

Really defined in math.h Have you tried including math.h and just using pow ? What do you mean by "can not find"?

+1
source share

If you are looking for how the calculation is done, you can find it here: http://fossies.org/dox/gcc-4.5.3/e__pow_8c_source.html The function name is __ieee754_pow which is called by the pow function.

+1
source share

Here's the C implementation for fdlibm: http://www.netlib.org/fdlibm/e_pow.c

What is it worth when v8 lowered its cos / sine tables, it pulled fdlibm from the implementation to do this: https://code.google.com/p/v8/source/detail?r=22918

From comments commenting on changes: "Implement trigonometric functions using the fdlibm port."

Mozilla, on the other hand, calls the cstdlib math functions, which will have variable assembly and system performance (for example, it may or may not cause chip-level implementations of transcendental functions). While C # bytecode seems to make explicit references to chip level functions when possible. However, "pow" is not one of them, iirc (does not seem to have a chip level function) and is implemented elsewhere.

See also: https://bugzilla.mozilla.org/show_bug.cgi?id=967709

For a discussion of cos / sine in the Mozilla community, a comparison of the Mozilla implementation and the old version of v8.

See also: How is Math.Pow () implemented in the .NET Framework?

Internal functions are the chip level actually implemented on the processor. (We no longer need search tables.)

+1
source share

here as well as here . Also go to wikipedia

Here you will find there.

0
source share

All Articles