WebApp Sec mailing list archives

Re: modulo question


From: Skip Carter <skip () taygeta com>
Date: Mon, 18 Apr 2005 12:47:01 -0700



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?

   Which is right depends upon whether you are using floored division
   or symmetrical (across zero) division.  I was on the ANS X3J14 (Forth)
   standards committee, and we debated this one endlessly.  In the end
   we adopted two different operators, one for each version, and pushed
   the choice of which to use to the code developer.





-- 
 Dr. Everett (Skip) Carter           Phone: 831-641-0645 FAX:  831-641-0647
 Taygeta Network Security Services   email: skip () taygeta net
 1340 Munras Ave., Suite 314         WWW: http://www.taygeta.net/
 Monterey, CA. 93940            











Attachment: _bin
Description:


Current thread: