Close

Java - Math.tanh() Examples

Java Java API 


Class:

java.lang.Math

java.lang.Objectjava.lang.Objectjava.lang.Mathjava.lang.MathLogicBig

Method:

public static double tanh(double x)

Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x)


Examples


package com.logicbig.example.math;

public class TanhExample {

public static void main(String... args) {
findHyperbolicTangent(90);
findHyperbolicTangent(60);
findHyperbolicTangent(45);
findHyperbolicTangent(30);
findHyperbolicTangent(0);
}

private static void findHyperbolicTangent(double angleInDegree) {
double angleInRadians = Math.toRadians(angleInDegree);
double tanh = Math.tanh(angleInRadians);
System.out.printf("Tanh of angle %s degree= %1.3f%n", angleInDegree, tanh);
}
}

Output

Tanh of angle 90.0 degree= 0.917
Tanh of angle 60.0 degree= 0.781
Tanh of angle 45.0 degree= 0.656
Tanh of angle 30.0 degree= 0.480
Tanh of angle 0.0 degree= 0.000




See Also