📜  Ruby CMath cos() 方法与示例

📅  最后修改于: 2022-05-13 01:54:21.281000             🧑  作者: Mango

Ruby CMath cos() 方法与示例

cos() 方法是 Math 类,用于返回给定值的余弦值。

示例 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