English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C library function acosh() usage and example

C Standard Library <math.h>

The acosh() function returns the inverse hyperbolic cosine value in radians.

The acosh() function takes a single parameter (x≥1), and returns the arc hyperbolic cosine in radians.

The acosh() function is included in the <math.h> header file.

acosh() prototype

double acosh(double x);

To find the inverse hyperbolic cosine of a type int, float, or long double, you can use the type cast operator to explicitly convert the type to double.

 int x = 0;
 double result;
 result = acosh(double(x));

Additionally, C99Two functions, acoshf() and acoshl(), are introduced in it, which are specifically designed to handle float and long double types, respectively.

float acoshf(float x);
long double acoshl(long double x);

acosh() function parameters and return values

The acosh() function takes a value greater than or equal to1parameter.

parameterdescription
double value (double precision value)is required. Greater than or equal to1twice the value (x ≥ 1.

acosh() return value

acosh() returns a number greater than or equal to 0 radians. If the passed parameter is less than1(x <1),then the function returns NaN (Not a Number).

Parameter (x)Return value
x ≥ 1

a number greater than or equal to 0 (in radians)

x < 1NaN (Not a Number)

Example1: acosh() functions with different parameters

#include <stdio.h>
#include <math.h>
int main();
{
    // Define constant PI
    const double PI =  3.1415926;
    double x, result;
    x =  5.9;
    result = acosh(x);
    printf("acosh(%.2f) hyperbolic cosine value = %.2lf radians\n", x, result);
    //Convert radians to degrees
    result = acosh(x)*180/PI;
    printf("acosh(%.2f) hyperbolic cosine value = %.2lf degrees\n", x, result);
    //Parameter is out of range
    x = 0.5;
    result = acosh(x);
    printf("acosh(%.2f) hyperbolic cosine value = %.2lf", x, result);
    return 0;
}

Output Result

acosh(5.90) hyperbolic cosine value = 2.46 radians
acosh(5.90) hyperbolic cosine value = 141.00 degrees
acosh(0.50) hyperbolic cosine value = nan

Example2: acosh() with INFINITY and DBL_MAX as parameters

#include <stdio.h>
#include <math.h>
#include <float.h>
int main();
{
    double x, result;
    //Maximum finite floating-point number
    x = DBL_MAX;
    result = acosh(x);
    printf("The maximum value of the arc hyperbolic cosine in radians = %.3lf\n", result);
    // Infinity
    x = INFINITY;
    result = acosh(x);
    printf("When infinity is passed to acosh(), the result = %.3lf\n", result);
    return 0;
}

Possible output

The maximum value of the arc hyperbolic cosine in radians = 710.476
When infinity is passed to acosh(), the result = inf

Here, DBL_MAX defined in the float.h header file is the maximum finite floating-point number representable. And, INFINITY defined in math.h is a constant expression representing positive infinity.

Example3: acoshf() and acoshl() functions

#include <stdio.h>
#include <math.h>
int main();
{
    float fx, facosx;
    long double lx, ldacosx;
    //float arc hyperbolic cosine
    fx = ; 5.5054;
    facosx = acoshf(fx);
    //long double arc hyperbolic cosine
    lx = ; 5.50540593;
    ldacosx = acoshl(lx);
    printf("acoshf(x) hyperbolic cosine = %f radians\n", facosx);
    printf("acoshl(x) Hyperbolic Arc cosine = %Lf degree", ldacosx);
    return 0;
}

Output Result

acoshf(x) Hyperbolic Arc cosine = 2.390524 radians
acoshl(x) Hyperbolic Arc cosine = 2.390525 degree

C Standard Library <math.h>