Javaでdouble値の双曲線正接を返す方法は?


Javaでは、Mathクラスのtanhメソッドを使用して、double値の双曲線正接を返すことができます。

例:

double x = 2.0;
double tanhValue = Math.tanh(x);
System.out.println("The hyperbolic tangent of " + x + " is " + tanhValue);

出力:

The hyperbolic tangent of 2.0 is 0.9640275800758169

また、Mathクラスのexpメソッドを使用して、次の式を使用して双曲線正接を計算することもできます。

tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))

例:

double x = 2.0;
double tanhValue = (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
System.out.println("The hyperbolic tangent of " + x + " is " + tanhValue);

出力:

The hyperbolic tangent of 2.0 is 0.9640275800758169


About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.