module BigDecimal::Internal

def self.coerce_to_bigdecimal(x, prec, method_name) # :nodoc:

:nodoc:
TODO: some methods (example: BigMath.exp) require more precision than specified to coerce.
Coerce x to BigDecimal with the specified precision.
def self.coerce_to_bigdecimal(x, prec, method_name) # :nodoc:
  case x
  when BigDecimal
    return x
  when Integer, Float
    return BigDecimal(x)
  when Rational
    return BigDecimal(x, [prec, 2 * BigDecimal.double_fig].max)
  end
  raise ArgumentError, "#{x.inspect} can't be coerced into BigDecimal"
end