Java - StrictMath atan(double) 方法



描述

Java StrictMath atan(double a) 返回一個角度的反正切值,範圍在 -pi/2 到 pi/2 之間。特殊情況 -

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

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

結果必須在正確舍入結果的 1 ulp 內。結果必須是半單調的。

宣告

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

public static double atan(double a)

引數

a − 要返回其反正切值的值。

返回值

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

異常

獲取角度的反正切示例

以下示例顯示了 StrictMath atan() 方法的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to PI/2
      double x = StrictMath.PI / 2;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc tangent of x
      System.out.println("StrictMath.atan(" + x + ")=" + StrictMath.atan(x));
   }
}

輸出

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

StrictMath.atan(0.027415567780803774)=0.0274087022410345

獲取 0° 角的反正切示例

以下示例顯示了 StrictMath atan() 方法在 0° 角情況下的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to zero
      double x = 0.0d;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc tangent of x
      System.out.println("StrictMath.atan(" + x + ")=" + StrictMath.tan(x));
   }
}

輸出

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

StrictMath.atan(0.0)=0.0

獲取 45° 角的反正切示例

以下示例顯示了 StrictMath atan() 方法在 45° 角情況下的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   public static void main(String[] args) {

      // get a variable x which is equal to zero
      double x = 45.0d;

      // convert x to radians
      x = StrictMath.toRadians(x);

      // get the arc tangent of x
      System.out.println("StrictMath.atan(" + x + ")=" + StrictMath.tan(x));
   }
}

輸出

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

StrictMath.atan(0.7853981633974483)=0.9999999999999999
java_lang_strictmath.htm
廣告

© . All rights reserved.