End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Float#/
self / other → numeric
numeric.c
View on GitHub ↗
VALUE
rb_float_div(VALUE x, VALUE y)
{
double num = RFLOAT_VALUE(x);
double den;
double ret;
if (FIXNUM_P(y)) {
den = FIX2LONG(y);
}
else if (RB_BIGNUM_TYPE_P(y)) {
den = rb_big2dbl(y);
}
else if (RB_FLOAT_TYPE_P(y)) {
den = RFLOAT_VALUE(y);
}
else {
return rb_num_coerce_bin(x, y, '/');
}
ret = double_div_double(num, den);
return DBL2NUM(ret);
}
Returns a new Float which is the result of dividing self by other:
Example
f = 3.14 f / 2 # => 1.57 f / 2.0 # => 1.57 f / Rational(2, 1) # => 1.57 f / Complex(2, 0) # => (1.57+0.0i)