Squeak archeology - quo vs. //

Dan Ingalls Dan at SqueakLand.org
Tue Apr 6 17:39:17 UTC 2004


>Hi Guys,
>
>Today I got very subtly bitten by // truncating towards negative infinity
>rather than zero, e.g.,
>
>    3//2 -> 1
>   -3//2 -> -2
>
>whereas:
>
>    3 quo: 2 -> 1
>   -3 quo: 2 -> -1
>
>The reason I got bitten is that the C translator generates // as C / which
>has the semantics of #quo:. Meaning that any translated code which uses
>integer divide with negative numbers will be subtly off.
>
>My question here (and that's the historical part) how comes that // rounds
>towards negative infinity?

Hi, Andreas -

I have always strongly disliked this particular convention.

Someone else was in charge of arithmetic (mainly LargeInts) when we settled on the ST-80 standard and I withdrew from the fray after expressing my opposition.  I was told that a lot of mathematicians (which I am not, in the formal sense) expect integer division to truncate toward negative infinity, and I had to trust that this was a good decision for Smalltalk.

I seriously considered "fixing" this when we did Squeak, but it would have been a disastrous incompatibility with the rest of the community.

	- Dan



More information about the Squeak-dev mailing list