C library - csinh() function



The C complex library csinh() function is used to calculate the hyperbolic sinh of z(complex number). The hyperbolic sine function has properties similar to the regular sine function except it is related to hyperbolas instead of circles.

The hyperbolic sine (sinh) complex number (z) is defined as:
sinh(z)= ez - e-z/2

This function is depends on the type of z(complex number). If the z is the "float" type, we use csinhf() to compute sinh, For long double type, use csinhl(), and for double type, use csinh().

Syntax

Following is the C library syntax of csinh() function −

double complex csinh( double complex z );

Parameters

This function accepts a single parameter −

  • Z − It represent a complex number for which we want to calculate sinh.

Return Value

This function returns the complex hyperbolic sine of z (complex number).

Example 1

Following is the basic c program to demonstrate the use of csinh() on a complex number.

#include <stdio.h>
#include <complex.h>

int main() {
   double complex z = 3.0 + 4.0 * I;

   // Calculate the sinh
   double complex res = csinh(z);
   printf("Complex sinh: %.2f%+.2fi\n", creal(res), cimag(res));

   return 0;
}

Output

Following is the output −

Complex sinh: -6.55-7.62i

Example 2

Let's see another example, calculate the hyperbolic sine of real line using csinh() function.

#include <stdio.h>
#include <math.h>
#include <complex.h>
 
int main(void)
{
    // real line
    double complex z = csinh(1);
    printf("sinh(1+0i) = %f+%fi (sinh(1)=%f)\n", creal(z), cimag(z), sinh(1));
}

Output

Following is the output −

Square root of -4 is 0.0+2.0i

Example 3

The below program, calculate the hyperbolic sine of the imaginary line using csinh() function.

#include <stdio.h>
#include <math.h>
#include <complex.h>
 
int main(void)
{
   // imaginary line
   double complex z2 = csinh(I); 
   printf("sinh(0+1i) = %f+%fi ( sin(1)=%f)\n", creal(z2), cimag(z2), sin(1));
}

Output

Following is the output −

sinh(0+1i) = 0.000000+0.841471i ( sin(1)=0.841471)
c_library_complex_h.htm
Advertisements