C Math Functions

There are various standard library functions and a macro defined under math.h to perform mathematical operations in C language. All the functions available in this library take double as an argument and return double as the result.

Math.h Library Functions :

Function Name Description
acos Calculates arc cosine of the argument
acosh Calculates hyperbolic arc cosine of the argument
asin Calculates arc sine of the argument
asinh Calculates hyperbolic arc sine of the argument
atan Calculates arc tangent of the argument
atanh Calculates hyperbolic arc tangent of the argument
atan2 Calculates arc tangent and determine the quadrant using sign
cbrt Calculates cube root of the argument
ceil Returns nearest integer greater than argument passed
cos Calculates the cosine of the argument
cosh Calculates the hyperbolic cosine of the argument
exp Calculates the e raised to given power
fabs Calculates absolute argument of floating point argument
floor Returns nearest integer lower than the argument passed.
hypot Calculates square root of sum of two arguments (Computes hypotenuse)
log Calculates natural logarithm
log10 Calculates logarithm of base argument 10
pow Calculates the number raised to given power
sin Calculates sine of the argument
sinh Calculates hyperbolic sine of the argument
sqrt Calculates square root of the argument
tan Calculates tangent of the argument
tanh Calculates hyperbolic tangent of the argument

There is only one macro defined in this library which is :

HUGE_VAL :  This macro is used when the result of a function may not be representable as a floating point number. If magnitude of the correct result is too large to be represented, the function sets errno to ERANGE to indicate a range error, and returns a particular, very large value named by the macro HUGE_VAL or its negation (- HUGE_VAL). And if the magnitude of the result is too small, a value of zero is returned instead. In this case, errno might or might not be set to ERANGE.

Example :
#include <stdio.h>
#include <math.h>

int main() {
  printf("cbrt(3) : %f\n", cbrt(3));
  printf("ceil(4.8763) : %f\n", ceil(4.8763));
  printf("cbrt(3) : %f\n", cbrt(3));
  printf("floor(3) : %f\n", floor(16.7564));
  printf("pow(5,2) : %f\n", pow(5,2));
  printf("sqrt(36) : %f\n", sqrt(36));
  return 0;
Output :

cbrt(3) : 1.442250
ceil(4.8763) : 5.000000
cbrt(3) : 1.442250
floor(3) : 16.000000
pow(5,2) : 25.000000
sqrt(36) : 6.000000

Next Topic :