# C programming cosh,coshf and coshl

In C programming the <math.h> cosh,coshf and coshl compute the hyperbolic cosine of the argument.The declaration of the functions are given below.

1 float cosh(float x);
2 double cosh(double x);
3 long double cosh(long double x);
4 float coshf(float x);
5 long double coshl(long double x);

Parameters:
x -The value whose hyperbolic cosine is to be computed.

Return type
floating point value -The hyperbolic cosine of ‘x’.

All the functions are the same,they compute the hyperbolic cosine of ‘x’.The 1st,2nd and the 3rd function have the same name i.e.’cosh’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note:

i) If the argument is very large Range error occur.In MINGW 6.1 and VS 2015 when x>710 ,Range error seems to occur.

ii)If NAN is passed ‘nan’ is returned.

iii)If INFINITY is passed ‘inf’ is returned.

Code example

double d=12 , x1=716 ;

float f=12 ;

long double ld=12 ;

printf(“%lf”, cosh( d ) ) ; //calls the 2nd version
printf(“\n%f”, cosh( f ) ) ; //calls the 1st version
printf(“\n%Lf”, cosh( ld ) ) ;//calls the 3rd version

printf(“\n%lf”, cosh( x1 ) ) ;
printf(“\n%lf”, cosh(INFINITY) ) ;

Output in Visual Studio ,

81377.395713
81377.395713
81377.395713
inf
inf

You can see the fourth output is ‘inf'(infinity) which shows that range error occurs for the argument value ‘716’.You can check the output for argument value 711 or more.

#### coshf

The ‘coshf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘coshf‘ stands for float and it signify the parameter and return type of the function.

Code example

float x= 123 ;

printf(“%f”, cosh( x ) ); //Calls the 1st version
printf(“\n%f”, coshf( 123 ) ); Calls the 4th version

Output,

5343237111808.000000
5343237111808.000000

#### coshl

The ‘coshl‘ function is same as the 3rd function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘coshl‘ stands for long double and it signify the parameter and return type of the function.

Code example

long double x= 123 ;

printf(“%Lf”, cosh( x ) ); //Calls the 3rd version
printf(“\n%Lf”, coshl( 123 ) ); //Calls the 5th version

Output,

5343237290762.231445
5343237290762.231445

Here you can see that the accuracy of the output of coshl and cosh(long double) are same but they are different from cosh(float) and coshf-which are the same for both- output.This obviously prove that they return a different data type values.