红宝石 |数学 cos()函数
cos()是 Ruby 中的一个内置函数,返回以弧度表示的给定角度的余弦值,该角度在[-inf, +inf]范围内。返回值在[-1, +1] 范围内。
Syntax: Math.cos(value)
Parameters: The function accepts one mandatory parameter value whose corresponding cosine value is returned.
Return Value: It returns the cosine value.
示例 1 :
#Ruby program for cos() function
#Assigning values
val1 = 1 val2 = 0.5 val3 = -1 val4 = -0.9
#Prints the cos() value
puts Math.cos(val1)
puts Math.cos(val2)
puts Math.cos(val3)
puts Math.cos(val4)
输出:
0.5403023058681398
0.8775825618903728
0.5403023058681398
0.6216099682706644
示例 2 :
#Ruby program for cos() function
#Assigning values
val1 = 109 val2 = 133 val3 = -13243 val4 = -9898
#Prints the cos() value
puts Math.cos(val1)
puts Math.cos(val2)
puts Math.cos(val3)
puts Math.cos(val4)
输出:
-0.577002178942952
0.4948722204034305
-0.37447564566939956
-0.40075875500376773
参考:https://devdocs.io/ruby~2.5/math#method-c-cos