The acos() is an inbuilt function in Ruby which returns the inverse cosine of a number (argument) in radians. The value which is returned by the acos() function always lies between –pi to +pi.
CPP
Output:
CPP
Output:
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.Example 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.3461938234056494Example 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