红宝石 |数学 tan()函数
tan()是 Ruby 中的一个内置函数,它返回以弧度表示的给定角度的正切,该角度在[-inf, +inf]范围内。返回值在[-inf, +inf] 范围内。
Syntax: Math.tan(value)
Parameters: The function accepts one mandatory parameter value whose corresponding tangent value is returned.
Return Value: It returns the tangent value.
示例 1 :
#Ruby program for tan() function
#Assigning values
val1 = 1 val2 = 0 val3 = 989 val4 = -8932
#Prints the tan() value
puts Math.tan(val1)
puts Math.tan(val2)
puts Math.tan(val3)
puts Math.tan(val4)
输出:
1.5574077246549023
0.0
-0.6866146142998235
-0.48563022371184766
示例 2 :
#Ruby program for tan() function
#Assigning values
val1 = -1023 val2 = 0.67 val3 = 98 val4 = -39
#Prints the tan() value
puts Math.tan(val1)
puts Math.tan(val2)
puts Math.tan(val3)
puts Math.tan(val4)
输出:
2.290822861412639
0.7922541747282569
0.6998536538095259
-3.614554407101535
参考:https://devdocs.io/ruby~2.5/math#method-c-tan