Gauche Devlog

< Constructing circular structures | Code is soft, interface is hard >

2010/06/18

div, mod, div0, mod0

In the process of implementing R6RS compatibility functions, I'm trying to represent R6RS's integer division div, mod, div0 and mod0 in terms of R5RS's integer division quotient, modulo and remainder, but I'm always confused with their behaviors when the divisor and/or the divident is/are negative. So I visualize them.

R5RS integer divisions:

[image] [image]

R6RS integer divisions:

[image] [image]

[image] [image]

I have a mixed feeling towards R6RS but I like this particular change; div/mod looks simpler and easier to explain (besides, not restricting arguments to integers is an interesting generalization).

To represent div/mod/div0/mod0 in terms of quotient/modulo/remainder, it looks that I have to branch for each case of 4 combinations of signs of divisor and dividend.

Tags: div, mod, r6rs

Post a comment

Name: