Create a new BigDecimal
object.
The initial value, as an Integer
, a Float
, a Rational
, a BigDecimal
, or a String
.
If it is a String
, spaces are ignored and unrecognized characters terminate the value.
The number of significant digits, as an Integer
. If omitted or 0, the number of significant digits is determined from the initial value.
The actual number of significant digits used in computation is usually larger than the specified number.
Whether an exception should be raised on invalid arguments. true
by default, if passed false
, just returns nil
for invalid.
If the initial
type is neither Integer
, Float
, Rational
, nor BigDecimal
, this exception is raised.
If the digits
is not an Integer
, this exception is raised.
If initial
is a Float
, and the digits
is larger than Float::DIG + 1, this exception is raised.
If the initial
is a Float
or Rational
, and the digits
value is omitted, this exception is raised.
static VALUE f_BigDecimal(int argc, VALUE *argv, VALUE self) { ENTER(1); Real *pv; VALUE obj; obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0); pv = BigDecimal_new(argc, argv); if (pv == NULL) return Qnil; SAVE(pv); if (ToValue(pv)) pv = VpCopy(NULL, pv); RTYPEDDATA_DATA(obj) = pv; RB_OBJ_FREEZE(obj); return pv->obj = obj; }