Ruby CMath cos() 方法与示例
cos() 方法是 Math 类,用于返回给定值的余弦值。
Syntax: Math.cos(z)
Parameter: Here, z is the value whose cosine is to be calculated.
Returns: This method returns the cosine value of the z.
示例 1:
# Ruby code for cos() method
require 'cmath'
# Initializing values
a = 0.3584
b = 2
# Printing result
puts "cos value of a : #{CMath.cos(a)}\n\n"
puts "cos value of b : #{CMath.cos(b)}\n\n"
输出:
cos value of a : 0.9364592642630104
cos value of b : -0.4161468365471424
示例 2:
# Ruby code for cos() method
require 'cmath'
# Initializing values
a = 0
b = -0.247
# Printing result
puts "cos value of a : #{CMath.cos(a)}\n\n"
puts "cos value of b : #{CMath.cos(b)}\n\n"
输出:
cos value of a : 1.0
cos value of b : 0.9696502723724634