This post lists the important functions available in the “math.h” library of C with their examples. Before continuing, you must know that we need to include the “math.h” library while compiling our program by using -lm ($cc -c filename.c $cc -o filename filename.c -lm).
Function Description Example
sqrt(x) square root of x sqrt(4.0) is 2.0
sqrt(10.0) is 3.162278
exp(x) exponential (ex) exp(1.0) is 2.718282
exp(4.0) is 54.598150
log(x) natural logarithm of x (base e) log(2.0) is 0.693147
log(4.0) is 1.386294
log10(x) logarithm of x (base 10) log10(10.0) is 1.0
log10(100.0) is 2.0
fabs(x) absolute value of x fabs(2.0) is 2.0
fabs(-2.0) is 2.0
ceil(x) rounds x to smallest integer not less than x
exp(x) exponential (ex) exp(1.0) is 2.718282
exp(4.0) is 54.598150
log(x) natural logarithm of x (base e) log(2.0) is 0.693147
log(4.0) is 1.386294
log10(x) logarithm of x (base 10) log10(10.0) is 1.0
log10(100.0) is 2.0
fabs(x) absolute value of x fabs(2.0) is 2.0
fabs(-2.0) is 2.0
ceil(x) rounds x to smallest integer not less than x
ceil(9.2) is 10.0
ceil(-9.2) is -9.0
floor(x) rounds x to largest integer not greater than x
ceil(-9.2) is -9.0
floor(x) rounds x to largest integer not greater than x
floor(9.2) is 9.0
floor(-9.2) is -10.0
pow(x,y) x raised to power y (xy) pow(2,2) is 4.0
fmod(x) remainder of x/y as floating-point number
floor(-9.2) is -10.0
pow(x,y) x raised to power y (xy) pow(2,2) is 4.0
fmod(x) remainder of x/y as floating-point number
fmod(13.657, 2.333) is 1.992
sin(x) sine of x (x in radian) sin(0.0) is 0.0
cos(x) cosine of x (x in radian) cos(0.0) is 1.0
tan(x) tangent of x (x in radian) tan(0.0) is 0.0
sin(x) sine of x (x in radian) sin(0.0) is 0.0
cos(x) cosine of x (x in radian) cos(0.0) is 1.0
tan(x) tangent of x (x in radian) tan(0.0) is 0.0
Comments
Post a Comment