Next: baselib math semantics trascend, Up: baselib math semantics [Index]
Scheme’s operations for performing integer division rely on mathematical operations div, mod, div_0, and mod_0, that are defined as follows:
x_1 div x_2 = n_d x_1 mod x_2 = x_m
where:
x_1 = n_d * x_2 + x_m 0 <= x_m < |x_2|
Examples:
123 div 10 = 12 123 mod 10 = 3 123 div -10 = -12 123 mod -10 = 3 -123 div 10 = -13 -123 mod 10 = 7 -123 div -10 = 13 -123 mod -10 = 7
x_1 div_0 x_2 = n_d x_1 mod_0 x_2 = x_m
where:
x_1 = n_d * x_2 + x_m -|x_2/2| <= x_m < |x_2/2|
Examples:
123 div_0 10 = 12 123 mod_0 10 = 3 123 div_0 -10 = -12 123 mod_0 -10 = 3 -123 div_0 10 = -12 -123 mod_0 10 = -3 -123 div_0 -10 = 12 -123 mod_0 -10 = -3