Section 5i

Using External Functions


 

 

 

 

 

 

 

 

 

 

 

 

Other People's Programming

One of the difficulties to writing simple programs is that some of the things we think are simple are actually kind of complex. It seems like it should be easy to get the square root of a number or take a number to an exponent power in a computer program but it turns out the code can get larger and more complicated than we need for our simple programs.

The use of library, or external, functions helps keep simple programs simple by providing commonly used mathematical functions to programmers who include the particular library in their programs. The most common library is the math.h library which can conduct the following actions, and many more.

sqrt, calculates the square root of a double value

sin, cos, tan, returns the appropriate trigonometric value, although it takes its input in the form of radians

pow, accepts a double base and exponent, and calculates the base to the power

There are thousands of other library functions that can conduct several different operations. You only need to look these up and apply them; in most cases you can just search for the name of the function you need on the Internet. As always, make sure you use a good reference and/or check on several sites to verify what you are finding.

Again, watch this video for more information about library functions. The program provided for this video is a good example of a testbed program where you can just check out how things work. Again, it is worth your while to try out the code and keep up your comfort level with whipping out programs.