acosh() Function

The acosh() function in C computes the inverse of the hyperbolic cosine, also known as the area hyperbolic cosine. It returns a nonnegative value corresponding to the area whose hyperbolic cosine yields the given input. This function is particularly useful in mathematical computations that involve inverse hyperbolic operations.


Syntax of acosh()

</>
Copy
double acosh(double x);

Parameters

ParameterDescription
xThe value for which the area hyperbolic cosine is computed. The value must be at least 1 to avoid a domain error.

Return Value

The function returns the nonnegative area hyperbolic cosine of the input value, in the interval [0, +INFINITY]. Note that the negative of this result is also mathematically valid.

If the input value is less than 1, a domain error occurs.


Examples for acosh()

Example 1: Computing the Area Hyperbolic Cosine for a Valid Input

This example demonstrates how to compute the area hyperbolic cosine using a valid input value that meets the required domain.

Program

</>
Copy
#include <stdio.h>
#include <math.h>

int main() {
    double value = 1.5;
    double result = acosh(value);
    printf("The area hyperbolic cosine of %.2f is %.2f\n", value, result);
    return 0;
}

Explanation:

  1. A valid input value (1.5) is chosen, which is within the acceptable range.
  2. The acosh() function computes the area hyperbolic cosine of the given value.
  3. The computed result is stored and then printed using printf().

Program Output:

The area hyperbolic cosine of 1.50 is 0.96

Example 2: Handling a Domain Error with an Invalid Input

This example illustrates the behavior of the acosh() function when provided with an input value that is below the required domain, thereby triggering a domain error.

Program

</>
Copy
#include <stdio.h>
#include <math.h>
#include <errno.h> 

int main() {
    double value = 0.5;
    errno = 0; // reset errno before calling acosh
    double result = acosh(value);
    if(errno == EDOM) {
        printf("Domain error: input value %.2f is less than 1\n", value);
    } else {
        printf("The area hyperbolic cosine of %.2f is %.2f\n", value, result);
    }
    return 0;
}

Explanation:

  1. An invalid input value (0.5) is used, which is below the minimum threshold of 1.
  2. This triggers a domain error; the function sets errno to EDOM if MATH_ERRNO is enabled.
  3. An error message is printed to notify the user about the domain error.

Program Output:

Domain error: input value 0.50 is less than 1