📜  红宝石 | BigDecimal cos()函数

📅  最后修改于: 2022-05-13 01:55:10.611000             🧑  作者: Mango

红宝石 | BigDecimal cos()函数

BigDecimal#cos() : cos()是一个 BigDecimal 类方法,它将余弦值返回到指定的精度位数,数字。

示例 #1:cos() 方法的示例

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

输出 :

BigDecimal a cos method : -0.83907152907645246825216692820607553E0

BigDecimal b cos method : 0.1E1

BigDecimal c cos method : 0.540302305868139718063666551191971443E0

示例 #2:

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

输出 :

BigDecimal a cos method : 0.81418097052656177616342509565903133E0

BigDecimal b cos method : 0.540302305868139717171666551191971443E0

BigDecimal c cos method : -0.9899924966004454524570754831726682E0