.tanh()
Anonymous contributor
Published Dec 18, 2022
Contribute to Docs
The Math.tanh()
method returns the hyperbolic sine of a double
-type value.
Syntax
Math.tanh(double num)
The .tanh()
method takes a single num
parameter that represents the angle (given in radians) whose hyperbolic tangent is to be determined. The return type of the .tanh()
method is a double
.
Some special cases for the .tanh()
method include the following:
- If
num
isNaN
, then the result isNaN
. - If
num
iszero
, then the result is azero
with the same sign as the argument. - If
num
ispositive
infinity, then the result is+1.0
. - If
num
isnegative
infinity, then the result is-1.0
.
The computed result will be within 2.5 units of least precision (ulps) of the exact result.
Example
The following example demonstrates the application of the .tanh()
method:
// Check.javapublic class Check {public static void main(String args[]) {// Value of num in degreesdouble num = 45.0;// Convert into radiansnum = Math.toRadians(num);// Compute and print hyperbolic tangentSystem.out.println(Math.tanh(num));}}
This results in the following output:
0.6557942026326724
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours