HaloO, Mark J. Reed wrote:
I believe mod should be defined in the conventional way: x mod y = x - floor(x/y) * y, which does yield 0.8 for 3.2 mod 2.4. However, for 3.2 mod - 2.4 it yields -1.6. To get 0.8 you would have to round toward zero instead of taking the floor, and that complicates any computation that crosses zero.
So, you are opting for the F-definition. Could you give examples where the E-definition makes problems when crossing zero? Looks like we need a host of division function pairs: fdiv fmod flooring division ediv emod euclidean division rdiv rmod rounding division tdiv tmod truncating division cdiv cmod ceiling division Note that the div functions have signature :(Num, Num --> Int) and the mod functions have signature :(Num ::T --> T). When called with Ints the mod funtions also return an Int. There should be a pair of operators div and % that is aliased to one of the above according to a pragma. The F-definition seems to be the default by popular demand. The / operator always returns a Num or perhaps has signature :(Num --> Num ^ Int) such that 8 / 2 == 4 gives an Int result. Even 1.6 / 0.4 == 4 might return an Int. But this means that / has to run a divisibility test and rounding errors might spoil this. E.g. (4/3) / (1/3) == 4.0000000003 is just almost an Int. The R-definition has the funny effect of returning a negative remainder even for positiv dividend and divisor. E.g. 8 rdiv 3 == 3 and 8 rmod 3 == -1. But this definition is used in the complex case of the Gaussian Integers. E.g. (12 + 5i) div (3 + 4i) == round(2.24 - 1.32i) == 2 - i and (12 + 5i) % (3 + 4i) == 2 BTW, we should define that the family of rounding functions floor, ceil, round and trunc all take a positiv modulus as their optional second argument that defines the jump width and height. The default is of course 1. E.g floor(1.3, 0.25) == 1.25 and floor(-2.7, 1.3) == -3.9. We could actually make these two optional positional parameters for width and height separately with the height the same as the width if not given and width defaulting to 1, as before. Regards, TSa. --