to_i()
Returns the value as an integer if possible (the imaginary part should be exactly zero).
Complex(1, 0).to_i #=> 1 Complex(1, 0.0).to_i # RangeError Complex(1, 2).to_i # RangeError
static VALUE nucomp_to_i(VALUE self) { get_dat1(self); if (!k_exact_zero_p(dat->imag)) { rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Integer", self); } return f_to_i(dat->real); }