当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StrictMath atan()用法及代码示例


java.lang.StrictMath.atan()是StrictMath类的内置方法,用于返回给定参数的切线。它返回的角度在-pi /2和pi /2的范围内。它产生两个特殊结果:

  • 如果传递的参数为NaN,则输出为NaN。
  • 如果传递的参数为0,则结果也是0,保留与参数相同的符号。

用法:

public static double atan(double num)

参数:该方法接受一个double类型的参数num,表示要返回其切线的值。


返回值:该方法返回参数的反正切值。

例子:

Input: num = 0.61
Output: 0.5477400137159024

Input: num = 0.0
Output: 0.0

Input: num = -71.0
Output: -1.5567127509720364

下面的程序演示了java.lang.StrictMath.atan()方法:
示例1:

// Java praogram to illustrate the 
// java.lang.StrictMath.atan() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = 0.70, num2 = 55.00, num3 = 0; 
  
        double atanValue = StrictMath.atan(num1); 
        System.out.println("The arc tangent of " +  
                         num1 + " = " + atanValue); 
  
        atanValue = StrictMath.atan(num2); 
        System.out.println("The arc tangent of " +  
                         num2 + " = " + atanValue); 
  
        atanValue = StrictMath.atan(num3); 
        System.out.println("The arc tangent of " +  
                          num3 + " = " + atanValue); 
    } 
}
输出:
The arc tangent of 0.7 = 0.6107259643892086
The arc tangent of 55.0 = 1.5526165117219184
The arc tangent of 0.0 = 0.0

示例2:

// Java praogram to illustrate the 
// java.lang.StrictMath.atan() 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        double num1 = -0.52, num2 = -71.00, num3 = 0; 
  
        double atanValue = StrictMath.atan(num1); 
        System.out.println("The arc tangent of " +  
                           num1 + " = " + atanValue); 
  
        atanValue = StrictMath.atan(num2); 
        System.out.println("The arc tangent of " +  
                            num2 + " = " + atanValue); 
  
        atanValue = StrictMath.atan(num3); 
        System.out.println("The arc tangent of " +  
                            num3 + " = " + atanValue); 
    } 
}
输出:
The arc tangent of -0.52 = -0.4795192919925962
The arc tangent of -71.0 = -1.5567127509720364
The arc tangent of 0.0 = 0.0


相关用法


注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StrictMath atan() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。