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
广告
© . All rights reserved.