Method: Integer#to_f

Defined in:
numeric.c

#to_fFloat

Converts self to a Float:

1.to_f  # => 1.0
-1.to_f # => -1.0

If the value of self does not fit in a Float, the result is infinity:

(10**400).to_f  # => Infinity
(-10**400).to_f # => -Infinity

Returns:



5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
# File 'numeric.c', line 5419

static VALUE
int_to_f(VALUE num)
{
    double val;

    if (FIXNUM_P(num)) {
        val = (double)FIX2LONG(num);
    }
    else if (RB_BIGNUM_TYPE_P(num)) {
        val = rb_big2dbl(num);
    }
    else {
        rb_raise(rb_eNotImpError, "Unknown subclass for to_f: %s", rb_obj_classname(num));
    }

    return DBL2NUM(val);
}