Method: Complex#to_i
- Defined in:
- complex.c
#to_i ⇒ Integer
Returns the value of self.real as an Integer, if possible:
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_)).
1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 |
# File 'complex.c', line 1799 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); } |