Math Functions

Remember to include the math.h header file; e.g., #include <math.h>

Note that M_PI is defined in <math.h> as 3.1415 ..  To 21 significant 
figures.  Thus, you may use M_PI in your code;

     float x = M_PI/4.0;

On all math functions, you must pass a double and a double is returned.  One 
easy way to do this when dealing with floats is to type cast the argument as 
a double and then type cast the returned value back to a float.

     y = (float) sin ( (double) x);

Trig functions include;

     double sin(double x)
     double cos(double x)
     double tan(double x)
     double sinh(double x)
     double cosh(double x)
     double tanh(double x)

Note that the arguement is the angle in radians.  Thus, if using degrees, 
first convert the arguement to radians;

     y = (float) sin ((double) ang_in_degreees * 2.0 * M_PI/360)

The following return the angle in radians.

     double asin(double x);
     double acos(double x);

     double atan(double x);   /* returns arctan value in quads I and IV */
     double atan2(double x, double y); /* returns value arctan of y/x */

Note the subtle difference in atan and atan2.


     double log (double x);       /* natural log - be careful of x <=0 */
     double log10 (double x);   /* log base 10 */

     double hypot(double x, double y);  /* returns hypotenuse of right 
     double sqrt (double x);  /* watch out for neg numbers */
     double pow(double x, double y); /* x^y */