Ruby - Math.atan() Method
The Ruby Math.atan() method returns arc tangent of a value. The returned value will be of float type and in the range -𝜋/2 through 𝜋/2.
Note: atan() is the inverse of tan().
Syntax
Math.atan(x)
Parameters
x |
Specify the value. |
Return Value
Returns the arc tangent of the value.
Example:
In the example below, Math.atan() method is used to find out the arc tangent of a given value.
puts "Math.atan(0) = #{Math.atan(0)}" puts "Math.atan(1) = #{Math.atan(1)}" puts "Math.atan(2) = #{Math.atan(2)}" puts "Math.atan(-1) = #{Math.atan(-1)}" puts "Math.atan(-2) = #{Math.atan(-2)}"
The output of the above code will be:
Math.atan(0) = 0.0 Math.atan(1) = 0.7853981633974483 Math.atan(2) = 1.1071487177940904 Math.atan(-1) = -0.7853981633974483 Math.atan(-2) = -1.1071487177940904
❮ Ruby Math Module