/*
 *  call-seq:
 *     num.remainder(numeric)    => result
 *  
 *  If <i>num</i> and <i>numeric</i> have different signs, returns
 *  <em>mod</em>-<i>numeric</i>; otherwise, returns <em>mod</em>. In
 *  both cases <em>mod</em> is the value
 *  <i>num</i>.<code>modulo(</code><i>numeric</i><code>)</code>. The
 *  differences between <code>remainder</code> and modulo
 *  (<code>%</code>) are shown in the table under <code>Numeric#divmod</code>.
 */

static VALUE
num_remainder(x, y)
    VALUE x, y;
{
    VALUE z = rb_funcall(x, '%', 1, y);

    if ((!rb_equal(z, INT2FIX(0))) &&
        ((RTEST(rb_funcall(x, '<', 1, INT2FIX(0))) &&
          RTEST(rb_funcall(y, '>', 1, INT2FIX(0)))) ||
         (RTEST(rb_funcall(x, '>', 1, INT2FIX(0))) &&
          RTEST(rb_funcall(y, '<', 1, INT2FIX(0)))))) {
        return rb_funcall(z, '-', 1, y);
    }
    return z;
}