void check(real n, real d) {
    real q = n // d;
    real r = n % d;
    assert(is_int(q), "non-integral quotient %v", q);
    assert(r >= 0, "negative remainder %v", r);
    assert(r < abs(d), "too-large remainder %v", r);
    real recons = q * d + r;
    assert(recons == n, "wrong reconstruction %v", recons);
}

void all_signs(real n, real d) {
    check(n, d);
    check(-n, d);
    check(n, -d);
    check(-n, -d);
}

all_signs(7, 3);
all_signs(7 * (1<<32), 3 * (1<<32));
all_signs(7/2, 3/2);
all_signs(imprecise(7/2), imprecise(3/2));
