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