Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Math atan() function

  • Last Updated : 07 Jan, 2020

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:






#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)

Output:

0.7853981633974483
0.4636476090008061
-0.7853981633974483
-0.7328151017865066

Example 2:




#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)

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
Recommended Articles
Page :

Start Your Coding Journey Now!