Java StrictMath tan() 方法



描述

Java StrictMath tan(double a) 返回角度的三角函式正切值。特殊情況 -

  • 如果引數是 NaN 或無窮大,則結果為 NaN。

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

計算結果必須在精確結果的 1 ulp 內。結果必須是半單調的。

宣告

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

public static double tan(double a)

引數

a − 以弧度為單位的角度。

返回值

此方法返回引數的正切值。

異常

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

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

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 tangent for this double
      System.out.println("StrictMath.tan(" + x + ")=" + StrictMath.tan(x));
   }
}

輸出

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

StrictMath.tan(0.7853981633974483)=0.9999999999999999

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

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

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 tangent for this double
      System.out.println("StrictMath.tan(" + x + ")=" + StrictMath.tan(x));
   }
}

輸出

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

StrictMath.tan(-0.7853981633974483)=-0.9999999999999999

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

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

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.tan(" + x + ")=" + StrictMath.tan(x));
   }
}

輸出

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

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