Method: Float#%

Defined in:
numeric.c

#%(other) ⇒ Float

Returns self modulo other as a float.

For float f and real number r, these expressions are equivalent:

f % r
f-r*(f/r).floor
f.divmod(r)[1]

See Numeric#divmod.

Examples:

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

Returns:



1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
# File 'numeric.c', line 1386

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));
}