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