Ruby | Math atan() function

The atan() is an inbuilt function in Ruby returns the arc tangent of a number means give a tangent value to this function it will return the angle in radian corresponding to that value. arc tangent is the inverse operation of tangent. This function accepts all numbers in range [-inf, +inf].

Syntax: Math.atan(value)

Parameters: The function accepts one mandatory parameter value whose corresponding angle we have to find.

Return Value: It returns the angle in radians which in range -pi/2 to +pi/2.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for atan() function
  
#Assigning values
val1 = 1 val2 = 0.5 val3 = -1 val4 = -0.9
  
#Prints the atan() value
                                      puts Math.atan(val1)
                                          puts Math.atan(val2)
                                              puts Math.atan(val3)
                                                  puts Math.atan(val4)

chevron_right


Output:

0.7853981633974483
0.4636476090008061
-0.7853981633974483
-0.7328151017865066

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for atan() function
  
#Assigning values
val1 = 0.9 val2 = 0.2 val3 = -0.78 val4 = -0.32
  
#Prints the atan() value
                                           puts Math.atan(val1)
                                               puts Math.atan(val2)
                                                   puts Math.atan(val3)
                                                       puts Math.atan(val4)

chevron_right


Output:

0.7328151017865066
0.19739555984988078
-0.6624262938331512
-0.3097029445424562

Reference: https://devdocs.io/ruby~2.5/math#method-c-atan




My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.