C++ cmath acosh , acoshf, acoshl function

The C++ cmath acosh, acoshf and acoshl function compute the arc hyperbolic cosine of the given value.The declaration of the functions is given below.

1 float acosh(float x);
2 double acosh(double x);
3 long double acosh(long double x);
4 float acoshf(float x);
5 long double acoshl(long double x);

Parameters:
x – A floating point non-negative value.

Return type
floating point value -The returned value is in the interval [0 , +∞].

Return type
floating point type -Returns the arc hyperbolic tangent of the given value.

The first function is called if the argument is float type.

The second function is called if the argument is double type.

Third function is called if the argument is long double type.

The 4th and 5th functions are discussed below.

Link : C++ asinh, asinhf and asinhl


Some points to note:

i) acosh(x) is same as cosh-1(x).

ii)The returned value is always +ve.

iii)If the argument is less than 1 a domain error occurs-a ‘nan’ is returned.

iv)If the arguments is integer or character literal the double version is called.

/*Passing floating point value*/
cout<< acosh(12) << endl ;

/*Passing 1*/
cout<< acosh(1) << endl ;

/*Passing 0*/
cout<< acosh( 0 ) << endl ;

/*Passing -ve value*/
cout<< acosh(-12) << endl ;

/*Passing INFINITY*/
cout<< acosh( INFINITY ) << endl ;

Output,

3.17631
0
nan
nan
nan



C++ acoshf

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

If any argument type other than the float type is passed to this function. The argument is converted to float type first and the arc hyperbolic cosine is computed. The function will constraint the argument and the returned value type to the float type.

cout<< acoshf( (double)45 )
   << "\n" << typeid( acoshf( (double)45) ).name() ;

cout<< "\nacoshf(-NAN)=" << acoshf( -NAN ) ;

Output,

4.49969
f
acoshf(-NAN)=nan


C++ acoshl

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

If any argument type other than the long double type is passed to this function. The argument is converted to long double type first and the arc hyperbolic cosine is computed. The function will constraint the argument and the returned value type to the long double type.

cout<< acoshl( (float)150 )
   << "\n" << typeid( acoshl( (float)150) ).name() ;

cout<< "\nacoshl(INFINITY)=" << acoshl( INFINITY ) ;

Output,

5.70377
e
acoshl(INFINITY)=nan




Leave a Reply

Your email address will not be published. Required fields are marked *