Ruby | Math cos() function

The cos() is an inbuilt function in Ruby returns the cosine value of a given angle expressed in radians which is in range [-inf, +inf]. The returned value is in range [-1, +1].

Syntax: Math.cos(value)

Parameters: The function accepts one mandatory parameter value whose corresponding cosine value is returned.



Return Value: It returns the cosine value.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

 0.5403023058681398
0.8775825618903728
0.5403023058681398
0.6216099682706644

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for cos() function
  
#Assigning values
val1 = 109 val2 = 133 val3 = -13243 val4 = -9898
  
#Prints the cos() value
                                            puts Math.cos(val1)
                                                puts Math.cos(val2)
                                                    puts Math.cos(val3)
                                                        puts Math.cos(val4)

chevron_right


Output:

-0.577002178942952
0.4948722204034305
-0.37447564566939956
-0.40075875500376773

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.