Embellished sample of the math library interface

This library contains various mathematical constants and functions.  To use the library you must compile your program with the -lm option:

gcc my_program.c -lm

(The option is a lowercase LM, not a 1m.)

// File math.h.
// Interface of the library math.
///////////////////////////////////////////////////////////

#ifndef _MATH_H
#define _MATH_H


///////////////////////////////////////////////////////////
// Section 1 -- Trigonometric functions 
///////////////////////////////////////////////////////////

double sin (double);
double cos (double);
double tan (double);


///////////////////////////////////////////////////////////
// Section 2 -- Exponentials and logarithms
///////////////////////////////////////////////////////////

// Returns e^x, that is, the number e raised to x. Usage:
// y = exp (x);

double exp (double);


// Returns the logarithm of x in base e. Do not use with
// x <= 0. Usage: y = log (x);

double log (double);


// Returns the logarithm of x in base 10. Do not use with
// x <= 0. Usage: y = log10 (x);

double log10 (double);


///////////////////////////////////////////////////////////
// Section 3 -- Roots and powers
///////////////////////////////////////////////////////////

// Returns the square root of x. Do not use with x < 0.
// Usage: y = sqrt (x);

double sqrt (double);


// Returns x^y, that is, x raised to the power y. Do not
// use with x == 0.0 and y < 0.0. Do not use with x < 0.0
// and noninteger y. Special case: pow (0.0, 0.0) == 1.0.
// What happens if x^y does not fit a double? See man
// pages. Usage: p = pow (x, y);

double pow (double, double);


///////////////////////////////////////////////////////////
// Section 4 -- Roundings
///////////////////////////////////////////////////////////

// This function returns the largest integer that is
// smaller than or equal to x, i.e., the only integer i
// that satisfies i <= x < i+1. Usage: i = floor (x);

double floor (double);


// This function returns the smallest integer that is
// greater than or equal to x, i.e., the only integer j
// that satisfies j-1 < x <= j. Usage: j = ceil (x);

double ceil (double);

#endif