Squeak archeology - quo vs. //

Hans-Martin Mosner hmm at heeg.de
Fri Apr 9 20:15:26 UTC 2004


Andreas Raab wrote:

>>As you have noted, especially in computer graphics this is an important
>>property, as you will have weird effects around zero if you round
>>towards zero.
>>    
>>
>
>Do you have any examples for this? 
>  
>
Suppose you have evenly spaced lines every 6 grid units:
(-15 to: 15 by: 6) asArray = #(-15 -9 -3 3 9 15)
Now you scale them down by a factor of two:
((-15 to: 15 by: 6) collect: [:i | i // 2]) = #(-8 -5 -2 1 4 7)
If you use #quo:, you get an uneven spacing (2 instead of 3) around zero:
((-15 to: 15 by: 6) collect: [:i | i quo: 2]) = #(-7 -4 -1 1 4 7)

Of course, I know that normally 2D in graphics you would do all 
transformations first, using floating point arithmetics, and only round 
to pixel coordinates in the last step where the values map to (positive) 
screen coordinates anyway, so this example is probably not entirely valid.

Another reason why the current // semantics have their merits is that 
they match well to bit operations when the quotient is a number of two:
(a // (2 raisedTo: n)) = (a bitShift: n negated)
(a \\ (2 raisedTo: n)) = (a bitAnd: (2 raisedTo: n)-1)
for integer values of a and positive integer values of n.

Cheers,
Hans-Martin





More information about the Squeak-dev mailing list