Namespaces
Variants
Views
Actions

cosh

From cppreference.com
< c‎ | numeric‎ | math
 
 
 
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99)
(C99)
(C99)(C99)(C99)
Exponential functions
(C99)
(C99)
(C99)
(C99)
Power functions
(C99)
(C99)
Trigonometric and hyperbolic functions
cosh
(C99)
(C99)
(C99)
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Nearest integer floating point operations
(C99)(C99)(C99)
(C99)
(C99)(C99)(C99)
Floating point manipulation functions
(C99)(C99)
(C99)
(C99)
Classification
(C99)
(C99)
(C99)
Macro constants
 
Defined in header <math.h>
float       coshf( float arg );
(since C99)
double      cosh( double arg );
long double coshl( long double arg );
(since C99)

Computes hyperbolic cosine of arg

Contents

[edit] Parameters

arg - floating point value

[edit] Return value

Hyperbolic cosine of arg

[edit] Example

#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <string.h>
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    printf("cosh(0.5)       = %f\n",    cosh(0.5));
    printf("acosh(1.127626) = %f\n",    acosh(1.127626));   /* inverse of cosh */
    printf("cosh(+0.0)      = %+.1f\n", cosh(+0.0));
    printf("cosh(-0.0)      = %+.1f\n", cosh(-0.0));
    printf("cosh(+INFINITY) = %+.1f\n", cosh(+INFINITY));
    printf("cosh(-INFINITY) = %+.1f\n", cosh(-INFINITY));
    printf("cosh(NAN)       = %f\n",    cosh(NAN));
    printf("\n");
 
    /* range error                                        */
    /* "inexact" and "overflow" floating-point exceptions */
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("cosh(DBL_MAX)   = %f\n",   cosh(DBL_MAX));
    printf("%s\n",strerror(errno));
    show_fe_exceptions();
 
    return 0;
}

Possible output:

cosh(0.5)       = 1.127626
acosh(1.127626) = 0.500000
cosh(+0.0)      = +1.0
cosh(-0.0)      = +1.0
cosh(+INFINITY) = +inf
cosh(-INFINITY) = +inf
cosh(NAN)       = nan
 
cosh(DBL_MAX)   = inf
Numerical result out of range
current exceptions raised:  FE_INEXACT FE_OVERFLOW

[edit] See also

computes hyperbolic sine (sh(x))
(function) [edit]
hyperbolic tangent
(function) [edit]
(C99)
area hyperbolic cosine
(function) [edit]