红宝石 |数学 acos()函数
acos()是 Ruby 中的一个内置函数,它以弧度返回数字(参数)的反余弦值。 acos()函数返回的值总是介于–pi到+pi之间。
Syntax: Math.acos(value)
Parameters: This function accepts one mandatory parameter value which specifies the value whose inverse cosine should be computed. It must lie between -1 and +1, else a domain-error is thrown.
Return Value: The function returns a numeric value between –pi and +pi. It is the counterclockwise angle which is measured in radian.
示例 1 :
#Ruby program for acos() function
#Assigning values
val1 = 1 val2 = -1 val3 = 0.5 val4 = -0.7
#Prints the acos() value
puts Math.acos(val1)
puts Math.acos(val2)
puts Math.acos(val3)
puts Math.acos(val4)
输出:
0.0
3.141592653589793
1.0471975511965979
2.3461938234056494
示例 2 :
#Ruby program for acos() function
#Assigning values
val1 = 0.8 val2 = -0.955 val3 = 0.74 val4 = -0.356
#Prints the acos() value
puts Math.acos(val1)
puts Math.acos(val2)
puts Math.acos(val3)
puts Math.acos(val4)
输出:
0.6435011087932843
2.8404561080364212
0.7377259684532488
1.9347802832764904