atanh() Function
The atanh()
function in C computes the area hyperbolic tangent of a given value. It performs the inverse operation of the hyperbolic tangent and is widely used in mathematical computations involving hyperbolic functions.
Syntax of atanh()
</>
Copy
double atanh(double x);
Parameters
Parameter | Description |
---|---|
x | Value whose area hyperbolic tangent is to be computed. The value must lie within the interval [-1, +1]. |
The function computes the inverse hyperbolic tangent. If the provided value is outside the interval [-1, +1], a domain error occurs. Additionally, for the boundary values of -1 and +1, a pole error may be signaled.
Examples for atanh()
Example 1: Computing the Area Hyperbolic Tangent for a Valid Positive Value
This example demonstrates how to compute the area hyperbolic tangent for a valid positive input using atanh()
.
Program
</>
Copy
#include <stdio.h>
#include <math.h>
int main() {
double value = 0.5;
double result = atanh(value);
printf("The area hyperbolic tangent of %.2f is %.5f\n", value, result);
return 0;
}
Explanation:
- A variable is declared and initialized with a valid positive value.
- The
atanh()
function is called with this value to compute its area hyperbolic tangent. - The result is printed to the console using
printf()
.
Program Output:
The area hyperbolic tangent of 0.50 is 0.54931
Example 2: Demonstrating Domain Error Handling with an Out-of-Range Input
This example illustrates how atanh()
behaves when the input value is outside the allowed interval, triggering a domain error.
Program
</>
Copy
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <string.h>
int main() {
errno = 0; // Reset errno before function call
double value = 2.0; // Out-of-range value for atanh()
double result = atanh(value);
if (errno != 0) {
perror("Error computing atanh");
} else {
printf("The area hyperbolic tangent is %.5f\n", result);
}
return 0;
}
Explanation:
- The program initializes a variable with a value outside the acceptable interval.
errno
is reset to detect any errors that may occur during the function call.- The
atanh()
function is invoked with the out-of-range value. - An error message is printed if a domain error occurs; otherwise, the computed result is displayed.
Program Output:
Error computing atanh: Numerical argument out of domain