Open In App

Ruby CMath cos() Method with example

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

cos() method is Math class which is used to returns the cosine of the given value.

Syntax: Math.cos(z)

Parameter: Here, z is the value whose cosine is to be calculated.

Returns: This method returns the cosine value of the z.

Example 1:




# Ruby code for cos() method
require 'cmath'
  
# Initializing values 
a = 0.3584
b = 2
  
# Printing result   
puts "cos value of a : #{CMath.cos(a)}\n\n" 
puts "cos value of b : #{CMath.cos(b)}\n\n"


Output:

cos value of a : 0.9364592642630104

cos value of b : -0.4161468365471424

Example 2:




# Ruby code for cos() method
require 'cmath'
  
# Initializing values  
a = 0
b = -0.247
  
# Printing result   
puts "cos value of a : #{CMath.cos(a)}\n\n"  
puts "cos value of b : #{CMath.cos(b)}\n\n"


Output:

cos value of a : 1.0

cos value of b : 0.9696502723724634

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads