Ruby | BigDecimal cos() function

BigDecimal#cos() : cos() is a BigDecimal class method which returns the value of cosine to the specified number of digits of precision, numeric.

Syntax: BigDecimal.cos()

Parameter: BigDecimal values



Return: the value of cosine to the specified number of digits of precision, numeric.

Example #1 : Example for cos() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for BigDecimal.cos() method
  
# loading library
require 'bigdecimal'
require 'bigdecimal/util'
  
require "bigdecimal/math"
  
include BigMath
  
# declaring bigdecimal
a = BigMath.cos(BigDecimal("10"), 2).to_s
  
# declaring bigdecimal
b = BigMath.cos(BigDecimal("0"), 1).to_s
  
# declaring bigdecimal
c = BigMath.cos(BigDecimal("-1"), 3).to_s
  
# cos() method
puts "BigDecimal a cos method : #{a}\n\n"
  
puts "BigDecimal b cos method : #{b}\n\n"
  
puts "BigDecimal c cos method : #{c}\n\n"

chevron_right


Output :

BigDecimal a cos method : -0.83907152907645246825216692820607553E0

BigDecimal b cos method : 0.1E1

BigDecimal c cos method : 0.540302305868139718063666551191971443E0

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for BigDecimal.cos() method
  
# loading library
require 'bigdecimal'
require 'bigdecimal/util'
  
require "bigdecimal/math"
  
include BigMath
  
# declaring bigdecimal
a = BigMath.cos(BigDecimal("120"), 2).to_s
  
# declaring bigdecimal
b = BigMath.cos(BigDecimal("1.0"), 4).to_s
  
# declaring bigdecimal
c = BigMath.cos(BigDecimal("-3"), 1).to_s
  
# cos() method
puts "BigDecimal a cos method : #{a}\n\n"
  
puts "BigDecimal b cos method : #{b}\n\n"
  
puts "BigDecimal c cos method : #{c}\n\n"

chevron_right


Output :

BigDecimal a cos method : 0.81418097052656177616342509565903133E0

BigDecimal b cos method : 0.540302305868139717171666551191971443E0

BigDecimal c cos method : -0.9899924966004454524570754831726682E0




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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.