Method: Rational#to_i
- Defined in:
- rational.c
#to_i ⇒ Integer
Returns the truncated value as an integer.
Equivalent to Rational#truncate.
Rational(2, 3).to_i #=> 0
Rational(3).to_i #=> 3
Rational(300.6).to_i #=> 300
Rational(98, 71).to_i #=> 1
Rational(-31, 2).to_i #=> -15
1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'rational.c', line 1282 static VALUE nurat_truncate(VALUE self) { get_dat1(self); if (INT_NEGATIVE_P(dat->num)) return rb_int_uminus(rb_int_idiv(rb_int_uminus(dat->num), dat->den)); return rb_int_idiv(dat->num, dat->den); } |