The mixing of reals and integers can be a "Got Ya" in lisp. As you can see if you use
integers for calculations you get integers BUT if you use one real your result will be a real.
This has caused more that one question here and added hours of debugging frustration
to many a programmer.
Also see FLOAT and FIX functions. There are many rounding routines here at The Swamp
if you need one.
PS I too have been guilty of reading the manual last.
CAB, I don't think the problem is with real vs. integer calculations. The help clearly states that if you use a real and integer, a real is returned.
In the example provided, (rem (+ sum a) 1000) should return 0.0 as (+ sum a) = 1000.0 that would mean that (rem 1000.0 1000) = 0.0 and would be correct, except (rem (+ sum a) 1000) returns 1000.0 .. clearly an incorrect return value. It would appear as though there is a float error in the mathematics.
Try these examples
(rem 1000.0 999.99999999999999) = 0.0
(rem 999.9999999999999 1000) = 1000.0
(rem 999.99999999999999 1000) = 0.0
In the function provided, the value of a is 256.2 (the remainder of 35256.2 / 1000), the value of sum is incremented by the value of b and sum, initialized at 0
Even forcing an evaluation of the value would incorrectly show that the value (eval (+ sum a)) is less than 1000, which is clearly not true.