method
to_i
v1_9_2_180 -
Show latest stable
- Class:
BigDecimal
to_i()public
Returns the value as an integer (Fixnum or Bignum).
If the BigNumber is infinity or NaN, raises FloatDomainError.
static VALUE
BigDecimal_to_i(VALUE self)
{
ENTER(5);
S_LONG e,nf;
Real *p;
GUARD_OBJ(p,GetVpValue(self,1));
BigDecimal_check_num(p);
e = VpExponent10(p);
if(e<=0) return INT2FIX(0);
nf = VpBaseFig();
if(e<=nf) {
e = VpGetSign(p)*p->frac[0];
return INT2FIX(e);
}
else {
VALUE a = BigDecimal_split(self);
VALUE digits = RARRAY_PTR(a)[1];
VALUE numerator = rb_funcall(digits, rb_intern("to_i"), 0);
S_LONG dpower = e - RSTRING_LEN(digits);
if (VpGetSign(p) < 0) {
numerator = rb_funcall(numerator, '*', 1, INT2FIX(-1));
}
if (dpower < 0) {
return rb_funcall(numerator, rb_intern("div"), 1,
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
INT2FIX(-dpower)));
}
return rb_funcall(numerator, '*', 1,
rb_funcall(INT2FIX(10), rb_intern("**"), 1,
INT2FIX(dpower)));
}
} Related methods
- Instance methods
- %
- *
- **
- +
- +@
- -
- -@
- /
- <
- <=
- <=>
- ==
- ===
- >
- >=
- _dump
- abs
- add
- ceil
- coerce
- div
- divmod
- eql?
- exponent
- finite?
- fix
- floor
- frac
- hash
- infinite?
- inspect
- modulo
- mult
- nan?
- nonzero?
- power
- precs
- quo
- remainder
- round
- sign
- split
- sqrt
- sub
- to_digits
- to_f
- to_i
- to_int
- to_r
- to_s
- truncate
- zero?
- Class methods
- _load
- double_fig
- limit
- mode
- new
- ver