Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


Using the C MATH library (3M)

There is a library of C functions called the "mathematics library" for
performing many common math functions.  There are functions such as sqrt, pow,
sin, cos, sinh, tanh, etc.  You can get a listing of the available functions
by using the 'man' command's '-k' option:

	man -k 3M  (or  man -k 3m  on the Sun workstations)

To learn more about any particular math function, again use the 'man' command
to view the individual manual page.  For example, to see the manual page for
the sqrt function, type this:

	man sqrt

You can also type:

	man math

for a list of many available functions, as well as details about the
mathematics behind them, and information on rounding errors, precisions,
and so forth.

When using the math functions in your C program, you need to do two things.

First, put the following line near the top of each C file that will use math
functions:

	#include <math.h>

This '#include' statement includes the proper declarations for the math
library functions.

Second, link with the math library when you are compiling your program.  To do
this, use the '-lm' option to the C compiler:

	cc program.c -lm

Make sure the '-lm' option is the last item on the line.  A common mistake is
to forget this option when compiling, which results in error messages
informing you that the math functions are undefined.


Last Updated: 7/25/96

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.