instance method
Float#%
(::Integer) -> ::Float
(::Float) -> ::Float
(::Rational) -> ::Float
(::Numeric) -> ::Numeric
self % other → float
numeric.c
View on GitHub ↗
static VALUE
flo_mod(VALUE x, VALUE y)
{
double fy;
if (FIXNUM_P(y)) {
fy = (double)FIX2LONG(y);
}
else if (RB_BIGNUM_TYPE_P(y)) {
fy = rb_big2dbl(y);
}
else if (RB_FLOAT_TYPE_P(y)) {
fy = RFLOAT_VALUE(y);
}
else {
return rb_num_coerce_bin(x, y, '%');
}
return DBL2NUM(ruby_float_mod(RFLOAT_VALUE(x), fy));
}
Returns self modulo other as a Float.
For float f and real number r, these expressions are equivalent:
Example
f % r f-r*(f/r).floor f.divmod(r)[1]
See Numeric#divmod.
Examples:
Example
10.0 % 2 # => 0.0 10.0 % 3 # => 1.0 10.0 % 4 # => 2.0 10.0 % -2 # => 0.0 10.0 % -3 # => -2.0 10.0 % -4 # => -2.0 10.0 % 4.0 # => 2.0 10.0 % Rational(4, 1) # => 2.0