[M3devel] how division and modulo work in hand.c?
Jay K
jay.krell at cornell.edu
Sun Jan 17 14:55:34 CET 2010
I have to admit I don't fully understand
the division and modulo code in hand.c.
I don't understand the old division code,
but the documenation and behavior are
clear: round down. I understand
why my version works, though it might
depend on non-guaranteed behavior in C division
for the same sign cases. An earlier version
was clearer since it avoided doing anything
with negative numbers execpt negating them
(and carefully at that).
Modulo is much less clear to me.
>From testing vs. the documentation, I know the
old code was wrong, though close.
I made some guesses based on the old code and
ran a variety of inputs through it.
My version matches the old version, except
where the old version is wrong.
I could write a clearly correct version, but it
would be perhaps much less efficient, just
computing a - b * div(a, b).
I tried running all 32bit inputs through some of it but it was
going to take too long.
I could maybe leave that running a few days if needed.
- Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20100117/cb1223c4/attachment-0001.html>
More information about the M3devel
mailing list