Module: Kernel
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#BigDecimal(initial, digits, exception: true) ⇒ Object
Create a new BigDecimal object.
Instance Method Details
#BigDecimal(initial, digits, exception: true) ⇒ Object
Create a new BigDecimal object.
- initial
-
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.
- digits
-
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.
- exception
-
Whether an exception should be raised on invalid arguments.
trueby default, if passedfalse, just returnsnilfor invalid.
Exceptions
- TypeError
-
If the
initialtype is neither Integer, Float, Rational, nor BigDecimal, this exception is raised. - TypeError
-
If the
digitsis not an Integer, this exception is raised. - ArgumentError
-
If
initialis a Float, and thedigitsis larger than Float::DIG + 1, this exception is raised. - ArgumentError
-
If the
initialis a Float or Rational, and thedigitsvalue is omitted, this exception is raised.
2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 |
# File 'ext/bigdecimal/bigdecimal.c', line 2867 static VALUE f_BigDecimal(int argc, VALUE *argv, VALUE self) { ENTER(1); Real *pv; VALUE obj; if (argc > 0 && CLASS_OF(argv[0]) == rb_cBigDecimal) { if (argc == 1 || (argc == 2 && RB_TYPE_P(argv[1], T_HASH))) return argv[0]; } obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0); pv = VpNewVarArg(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; } |