instance method
Complex#to_i
() -> ::Integer
to_i → integer
complex.c
View on GitHub ↗
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);
}
Returns the value of self.real as an Integer, if possible:
Example
Complex.rect(1, 0).to_i # => 1 Complex.rect(1, Rational(0, 1)).to_i # => 1
Raises RangeError if self.imag is not exactly zero (either Integer(0) or Rational(0, _n_)).