Ruby BigDecimal cos()函数
BigDecimal#cos() : cos()是BigDecimal类的一个方法,用于返回指定精度位数的余弦值,数值型。
语法。BigDecimal.cos()
参数。大十进制的数值
返回:余弦值,精度为指定位数,数值。
例子#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