Method: BigMath.cos

Defined in:
lib/bigdecimal/math.rb

.cos(x, prec) ⇒ Object

call-seq:

cos(decimal, numeric) -> BigDecimal

Computes the cosine of decimal to the specified number of digits of precision, numeric.

If decimal is Infinity or NaN, returns NaN.

BigMath.cos(BigMath.PI(16), 32).to_s
#=> "-0.99999999999999999999999999999997e0"


124
125
126
127
128
129
130
# File 'lib/bigdecimal/math.rb', line 124

def cos(x, prec)
  prec = BigDecimal::Internal.coerce_validate_prec(prec, :cos)
  x = BigDecimal::Internal.coerce_to_bigdecimal(x, prec, :cos)
  return BigDecimal::Internal.nan_computation_result if x.infinite? || x.nan?
  sign, x = _sin_periodic_reduction(x, prec + BigDecimal.double_fig, add_half_pi: true)
  sign * sin(x, prec)
end