Hyperbolic Functions in C Standard Library

What are Hyperbolic Functions?

Hyperbolic functions are similar to trigonometric functions, but they are based on hyperbolas instead of circles. These functions are widely used in engineering, physics, and mathematical modeling.

Here are the three main hyperbolic functions:

  • sinh(x) – Hyperbolic sine
  • cosh(x) – Hyperbolic cosine
  • tanh(x) – Hyperbolic tangent

Syntax of Hyperbolic Functions in C

In C, hyperbolic functions are defined in the math.h header file. You must include this file and link the math library during compilation using -lm (on Linux-based systems).

#include <math.h>

Here are the function prototypes:

double sinh(double x);
double cosh(double x);
double tanh(double x);

All three functions take a double value as input and return a double.

advertisement

Mathematical Formulas

For reference, here are the mathematical definitions:

  • sinh(x) = (e^x – e^(-x)) / 2
  • cosh(x) = (e^x + e^(-x)) / 2
  • tanh(x) = sinh(x) / cosh(x)

These formulas use Euler’s number e, which is approximately 2.71828.

sinh() – Hyperbolic Sine

Returns the hyperbolic sine of a number.

Formula: sinh(x) = (e^x – e^(-x)) / 2

Free 30-Day Python Certification Bootcamp is Live. Join Now!

Syntax:

double sinh(double x);

Example:

#include <stdio.h>
#include <math.h>
 
int main() {
    double quiz = 1.0;
    printf("sinh(%f) = %f\n", quiz, sinh(quiz));
    return 0;
}

Output:

sinh(1.000000) = 1.175201

This C program demonstrates the use of the sinh() function from the math library. It declares a variable quiz with the value 1.0 and uses sinh(quiz) to calculate the hyperbolic sine of that value. The result is then printed.

cosh() – Hyperbolic Cosine

Returns the hyperbolic cosine of a number.

Formula: cosh(x) = (e^x + e^(-x)) / 2

Syntax:

advertisement
double cosh(double x);

Example:

#include <stdio.h>
#include <math.h>
 
int main() {
    double test = 1.0;
    printf("cosh(%f) = %f\n", test, cosh(test));
    return 0;
}

Output:

cosh(1.000000) = 1.543081

This C program shows how to use the cosh() function from the math library. It sets a variable test to 1.0 and calculates the hyperbolic cosine of that value using cosh(test). The result is printed.

tanh() – Hyperbolic Tangent

Returns the hyperbolic tangent of a number.

Formula: tanh(x) = sinh(x) / cosh(x)

Syntax:

double tanh(double x);

Example:

#include <stdio.h>
#include <math.h>
 
int main() {
    double mcqs = 1.0;
    printf("tanh(%f) = %f\n", mcqs, tanh(mcqs));
    return 0;
}

Output:

tanh(1.000000) = 0.761594

This C program demonstrates the use of the tanh() function from the math library. It assigns the value 1.0 to the variable mcqs and computes its hyperbolic tangent using tanh(mcqs). The result is printed, showing how to use <math.h> for hyperbolic functions in C.

Inverse Hyperbolic Functions

C also offers functions to compute the inverse of hyperbolic functions:

  • asinh(x): Inverse hyperbolic sine
  • acosh(x): Inverse hyperbolic cosine (domain: x ≥ 1)
  • atanh(x): Inverse hyperbolic tangent (domain: -1 < x < 1)

Syntax:

Inverse hyperbolic functions in C are available via the math.h header (from C99 standard onward):

#include <math.h>

Function prototypes:

double asinh(double x);
double acosh(double x);
double atanh(double x);

All functions take a double input and return a double.

Mathematical Definitions

Here are the formulas used behind the scenes:

  • asinh(x) = ln(x + sqrt(x2 + 1))
  • acosh(x) = ln(x + sqrt(x2 – 1)) (only valid for x ≥ 1)
  • atanh(x) = 0.5 × ln((1 + x) / (1 – x)) (only valid for -1 < x < 1)

These use natural logarithm ln, which is the log to base e.

Example of Inverse Hyperbolic Functions

#include <stdio.h>
#include <math.h>
 
int main()
{
    double quizScore = 1.5;
    double testScore = 2.0;
    double certificationRatio = 0.6;
 
    printf("asinh: %f\n", asinh(quizScore));
    printf("acosh: %f\n", acosh(testScore));
    printf("atanh: %f\n", atanh(certificationRatio));
 
    return 0;
}

Output:

asinh: 1.194763
acosh: 1.316958
atanh: 0.693147

This C program demonstrates the use of inverse hyperbolic functions from the math library. It defines three variables and uses asinh(), acosh(), and atanh() to calculate the inverse hyperbolic sine, cosine, and tangent, respectively. The results are printed, showing how to apply these functions using <math.h> in C.

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.