El 19/04/2012 12:00, Bryan Horstmann escribió:
I've had a look at Python too, Malcolm, and found "Python Languages & Syntax
Cheat Sheet". Under basic arithmetic it says "i=a%b e.g. 11%3 > 2" I cannot make
sense of that.
That's the modulus operator, as in C language. The binary operator a%b returns
the remainder of the integer division between "a" and "b". It's equivalent to
the MOD function in SBASIC.
For example, 11%3 returns 2 because 11 divided by 3 gives 3 and remainder 2.
It's a very powerfull operator to perform modular aritmethic. For example,
imagine that you want to calculate fast sine functions, and to to that, you have
set up a table with 360 numbers, indexed from 0 to 359. Element with index "i"
will contain the sine of "i" (with "i" expressed in degrees).
Then, for an arbitrary (positive integer) angle, you can do something like:
sineofi = sinetable[i%360];
The index expression inside the brackets will wrap around 360, giving you
0,1,2,...,358,359,0,1,....
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm