Java - StrictMath tanh(double x) 方法



描述

Java StrictMath tanh(double x) 方法返回雙精度值的雙曲正切值。x 的雙曲正切定義為 (ex - e-x)/(ex + e-x),換句話說,sinh(x)/cosh(x)。請注意,精確 tanh 的絕對值始終小於 1。特殊情況 -

  • 如果引數是 NaN,則結果是 NaN。

  • 如果引數是零,則結果是與引數符號相同的零。

  • 如果引數是正無窮大,則結果是 +1.0。

  • 如果引數是負無窮大,則結果是 -1.0。

計算結果必須在精確結果的 2.5 ulps 以內。任何有限輸入的 tanh 結果的絕對值必須小於或等於 1。請注意,一旦 tanh 的精確結果在 1 的極限值的 1/2 ulp 以內,就應該返回正確符號的 1.0。

宣告

以下是 java.lang.StrictMath.tanh() 方法的宣告

public static double tanh(double x)

引數

x − 要返回其雙曲正切值的數字。

返回值

此方法返回 x 的雙曲正切值。

異常

示例:獲取正雙精度值的雙曲正切值。

以下示例演示瞭如何使用 StrictMath tanh() 方法獲取正雙精度值的雙曲正切值。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = 45.0;

      // convert it to radian
      x = StrictMath.toRadians(x);

      // print the hyperbolic tangent for this double
      System.out.println("StrictMath.tanh(" + x + ")=" + StrictMath.tanh(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.tanh(0.7853981633974483)=0.6557942026326724

示例:獲取負雙精度值的雙曲正切值。

以下示例演示瞭如何使用 StrictMath tanh() 方法獲取負雙精度值的雙曲正切值。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = -45.0;

      // convert it to radian
      x = StrictMath.toRadians(x);

      // print the hyperbolic tangent for this double
      System.out.println("StrictMath.tanh(" + x + ")=" + StrictMath.tanh(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.tanh(-0.7853981633974483)=-0.6557942026326724

示例:獲取零雙精度值的雙曲正切值。

以下示例演示瞭如何使用 StrictMath tanh() 方法獲取零雙精度值的雙曲正切值。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

      // convert it to radian
      x = StrictMath.toRadians(x);

      // print the hyperbolic tangent for this double
      System.out.println("StrictMath.tanh(" + x + ")=" + StrictMath.tanh(x));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

StrictMath.tanh(0.0)=0.0
java_lang_strictmath.htm
廣告