Ruby Tutorial Ruby Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Ruby - Math.acos() Method



The Ruby Math.acos() method returns arc cosine of a value. The return value will be of float type and in the range 0 through 𝜋.

Note: acos() is the inverse of cos().

Syntax

Math.acos(x)

Parameters

x Specify the value.

Return Value

Returns the arc cosine of the value.

Example:

In the example below, Math.acos() method is used to find out the arc cosine of a given value.

puts "Math.acos(0) = #{Math.acos(0)}"
puts "Math.acos(0.5) = #{Math.acos(0.5)}"
puts "Math.acos(1) = #{Math.acos(1)}"
puts "Math.acos(-0.5) = #{Math.acos(-0.5)}"
puts "Math.acos(-1) = #{Math.acos(-1)}"

The output of the above code will be:

Math.acos(0) = 1.5707963267948966
Math.acos(0.5) = 1.0471975511965979
Math.acos(1) = 0.0
Math.acos(-0.5) = 2.0943951023931957
Math.acos(-1) = 3.141592653589793

❮ Ruby Math Module

5