Java Number类

说明

Java Math atan(double a) 返回角度的反正切值,范围为 -pi/2 到 pi/2。特殊情况 -

  • 如果参数为 NaN,则结果为 NaN。

  • 如果参数为零,则结果是与参数具有相同符号的零。

结果必须在正确舍入结果的 1 ulp 范围内。结果必须是半单调的。

语法

public static double atan(double d)

参数

这里是参数的详细信息 -

  • d - 双精度数据类型。

返回值

  • 此方法返回指定双精度值的反正切值。

示例 1

在此示例中,我们将展示用法Math.atan() 方法获取双精度数的atan。我们创建了一个双精度变量 x 并用给定的角度初始化它。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.atan() 方法打印 atan 值。

public class Test {
   public static void main(String args[]) {
      double degrees = 45.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arctangent of %.1f degrees is %.4f%n", degrees, Math.atan(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arctangent of 45.0 degrees is 0.6658

示例 2

在此示例中,我们将展示如何使用 Math.atan() 方法来获取浮点数的 atan。我们创建了一个浮点变量 x 并用给定的角度初始化它。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.atan() 方法打印 atan 值。

public class Test {
   public static void main(String args[]) {
      float degrees = (float)45.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arctangent of %.1f degrees is %.4f%n", degrees, Math.atan(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arctangent of 45.0 degrees is 0.6658

示例 3

在此示例中,我们将展示如何使用 Math.atan() 方法来获取零值的 tan。我们创建了一个浮点变量 x 并使用给定角度将其初始化为零值。然后使用 Math.toRadians() 方法检索弧度,然后使用 Math.atan() 方法打印 atan 值。

public class Test {
   public static void main(String args[]) {
      float degrees = (float)0.0;
      double radians = Math.toRadians(degrees);

      System.out.format("The value of pi is %.4f%n", Math.PI);
      System.out.format("The arc tangent of %.1f degrees is %.4f%n", degrees, Math.atan(radians));
   }
}

这将产生以下结果 -

输出

The value of pi is 3.1416
The arc tangent of 0.0 degrees is 0.0000