sinh() Function

The sinh() function computes the hyperbolic sine of a given value. It is part of the C math library and provides a way to obtain the hyperbolic sine, which is useful in various mathematical computations involving hyperbolic functions.


Syntax of sinh()

</>
Copy
double sinh(double x);
float sinhf(float x);
long double sinhl(long double x);

Parameters

ParameterDescription
xValue representing a hyperbolic angle (in radians).

Return Value

The function returns the hyperbolic sine of the given value. In case of an overflow, the appropriate HUGE_VAL constant is returned and an overflow range error is triggered.


Examples for sinh()

Example 1: Computing Hyperbolic Sine for a Positive Angle

This example demonstrates how to compute the hyperbolic sine of a positive value using sinh().

Program

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

int main() {
    double value = 1.0;
    double result = sinh(value);
    printf("sinh(%f) = %f\n", value, result);
    return 0;
}

Explanation:

  1. The variable value is initialized with a positive angle (in radians).
  2. The sinh() function computes the hyperbolic sine of this value.
  3. The result is then printed to the console.

Program Output:

sinh(1.000000) = 1.175201

Example 2: Computing Hyperbolic Sine for a Negative Angle

This example demonstrates the computation of the hyperbolic sine for a negative value.

Program

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

int main() {
    double value = -1.0;
    double result = sinh(value);
    printf("sinh(%f) = %f\n", value, result);
    return 0;
}

Explanation:

  1. The variable value is set to a negative angle.
  2. The sinh() function calculates the hyperbolic sine for this negative value.
  3. The result, which is negative, is printed to the console.

Program Output:

sinh(-1.000000) = -1.175201

Example 3: Handling Large Values Leading to Overflow

This example shows how the sinh() function behaves when the input is so large that it causes an overflow.

Program

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

int main() {
    errno = 0;
    double value = 1000.0;
    double result = sinh(value);
    if(errno == ERANGE) {
        printf("Overflow occurred, result = %f\n", result);
    } else {
        printf("sinh(%f) = %f\n", value, result);
    }
    return 0;
}

Explanation:

  1. The variable value is assigned a large number, which may result in an overflow.
  2. The global variable errno is reset to 0 before calling sinh().
  3. The sinh() function is called, and the result is checked for an overflow error.
  4. If an overflow occurs, an appropriate message is printed along with the result.

Program Output:

Overflow occurred, result = inf