digits(*args)
public
Returns the array including the digits
extracted by place-value notation with radix base of int.
base should be greater than or equal to 2.
12345.digits
12345.digits(7)
12345.digits(100)
-12345.digits(7)
Show source
static VALUE
rb_int_digits(int argc, VALUE *argv, VALUE num)
{
VALUE base_value;
long base;
if (rb_num_negative_p(num))
rb_raise(rb_eMathDomainError, "out of domain");
if (rb_check_arity(argc, 0, 1)) {
base_value = rb_to_int(argv[0]);
if (!RB_INTEGER_TYPE_P(base_value))
rb_raise(rb_eTypeError, "wrong argument type %s (expected Integer)",
rb_obj_classname(argv[0]));
if (RB_TYPE_P(base_value, T_BIGNUM))
return rb_int_digits_bigbase(num, base_value);
base = FIX2LONG(base_value);
if (base < 0)
rb_raise(rb_eArgError, "negative radix");
else if (base < 2)
rb_raise(rb_eArgError, "invalid radix %ld", base);
}
else
base = 10;
if (FIXNUM_P(num))
return rb_fix_digits(num, base);
else if (RB_TYPE_P(num, T_BIGNUM))
return rb_int_digits_bigbase(num, LONG2FIX(base));
return Qnil;
}