APIdock / Ruby
/
method

to_f

ruby latest stable - Class: Complex
to_f()
public

Returns the value as a float if possible (the imaginary part should be exactly zero).

Complex (1, 0).to_f  #=> 1.0
Complex (1, 0.0).to_f  # RangeError
Complex (1, 2).to_f  # RangeError
static VALUE
nucomp_to_f(VALUE self)
{
 get_dat1(self);
 if (!k_exact_zero_p(dat->imag)) {
 rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Float",
 self);
 }
 return f_to_f(dat->real);
}

AltStyle によって変換されたページ (->オリジナル) /