Ruby CMath atan() 方法与示例
atan() 方法是 CMath 类,用于返回给定值的反正切。
Syntax: Math.atan(z)
Parameter: Here, z is the value whose arc tangent is to be calculated.
Returns: This method returns the arc tangent value of the z.
示例 1:
# Ruby code for atan() method
require 'cmath'
# Initializing value
a = 0.3584
b = 2
# Printing result
puts "atan value of a : #{CMath.atan(a)}\n\n"
puts "atan value of b : #{CMath.atan(b)}\n\n"
输出:
atan value of a : 0.34413842830780517
atan value of b : 1.1071487177940904
示例 2:
# Ruby code for atan() method
require 'cmath'
# Initializing value
a = 0
b = -0.247
# Printing result
puts "atan value of a : #{CMath.atan(a)}\n\n"
puts "atan value of b : #{CMath.atan(b)}\n\n"
输出:
atan value of a : 0.0
atan value of b : -0.24215314674687552