chickadee » srfi-94 » mod

modprocedure

x2 should be non-zero.

(quo x1 x2)                     ==> n_q
(rem x1 x2)                     ==> x_r
(mod x1 x2)                     ==> x_m

where n_q is x1/x2 rounded towards zero, 0 < |x_r| < |x2|, 0 < |x_m| < |x2|, x_r and x_m differ from x1 by a multiple of x2, x_r has the same sign as x1, and x_m has the same sign as x2.

From this we can conclude that for x2 not equal to 0,

(= x1 (+ (* x2 (quo x1 x2))
      (rem x1 x2)))
                                  ==>  #t

provided all numbers involved in that computation are exact.

(quo 2/3 1/5)                          ==>  3
(mod 2/3 1/5)                  ==>  1/15

(quo .666 1/5)                 ==>  3.0
(mod .666 1/5)                 ==>  65.99999999999995e-3