C++ cmath cosh function


The C++ <cmath> cosh,coshf and coshl functions compute the hyperbolic cosine of the given value.

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 – A floating point value.

Return type
floating point -Hyperbolic cosine of x.

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

/*passing 710 */
cout<< “cosh(710)=” << cosh(710) << endl

/*passing 711 */
cout<< “cosh(711)=” << cosh(711) << endl

/*passing NAN */
cout<< “cosh(NAN)=” << cosh(NAN) << endl

/*passing INFINITY */
cout<< “cosh(INFINITY)=” << cosh(INFINITY) << endl

Output

cosh(710) = 1.117e+308
cosh(711) = inf
cosh(NAN) = nan
cosh(INFINITY) = inf



coshf and coshl

*Note

i)The 4th version coshf is same as the 1st version float cosh(float).The ‘f‘ character stands for ‘float’ which signify the argument and return type of the function.

ii)The 5th version coshl is same as the 3rd version long double cosh(long double).The ‘l‘ character stands for ‘long double’ which signify the argument and return type of the function.

Code example

#include <typeinfo>

/*coshf */
cout<< “*coshf\n”;
float f=2;
cout<< typeid( coshf(2) ).name() << endl /*identify type of coshf retunred value */
<< typeid( cosh(f) ).name() << endl; /*identify type of cosh(float) returned value */

/*coshl*/
cout<< “*coshl\n”;
long double ld=2;
cout<< typeid( coshl(2) ).name() << endl /*indentify type of coshl returned value */
<< typeid( cosh(ld) ).name() << endl; /*identify type of cosh(long double) returned value*/

Output

*coshf
f
f
*coshl
e (means ‘long double’)
e (means ‘long double’)





(adsbygoogle = window.adsbygoogle || []).push({});