WebApp Sec mailing list archives
Re: modulo question
From: Scovetta Labs <security () scovettalabs com>
Date: Mon, 18 Apr 2005 21:11:25 -0400
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Martin, I'm not sure if this is "correct", but as per: http://www.oremus.org/liturgy/etc/ktf/app/modulo.html "A subtle point is that the remainder is always a positive number. So -7 divided by 3 is -3, remainder 2 (rather than -2, remainder -1)." So (-1)%2 should be 1, because 2*(-1) + 1 = -1 ~ 1%(-2) should be 1, because (-2)*(0) + 1 = 1 Of course, this could be totally wrong, if I'm missing something from the fundamental definition of modulo arithmetic. Also, python and C++ might bind the % and - operators at difference precedence levels-- use parentheses to make sure. - -Mike martin wrote: | Hello list, | | I have slightly academic question about modulo. I sent this message here | because I thing there are many of gurus which working with modulo operator. | | I have tried in python and in C++ following: | python C++ | 1%2 1 1 | -1%2 1 -1 | 1%-2 -1 1 | -1%-2 -1 -1 | | What is right? | Do you know some applications which using modulo with negative numbers? | Have you some references to definition (mathematical def. and properties) of | modulo? | | Thanks in advance, | Martin - -- Michael Scovetta Scovetta Labs www.scovettalabs.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCZFq5K5Y2cJWwwk0RAjU3AJwMCpD8t5wHc/p/IU5bJjIwLWITWwCffYIc kELqpCfvdrqhckAYItbMhe4= =+a7b -----END PGP SIGNATURE-----
Current thread:
- modulo question martin (Apr 18)
- Re: modulo question Michael Vergoz (Apr 20)
- Re: modulo question Skip Carter (Apr 20)
- Re: modulo question Scovetta Labs (Apr 20)
- Re: modulo question Federico CastaƱeda (Apr 20)
- Re: modulo question Kelly John Rose (Apr 20)
- Re: modulo question warnings (Apr 21)