Xref: utzoo comp.theory:380 comp.misc:8304 comp.lang.misc:4241 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!cam-cl!cet1 From: cet1@cl.cam.ac.uk (C.E. Thompson) Newsgroups: comp.theory,comp.misc,comp.lang.misc Subject: Re: Modulus (Re: hashing function for strings) Message-ID: <1776@gannet.cl.cam.ac.uk> Date: 23 Feb 90 14:53:13 GMT References: <981@m1.cs.man.ac.uk> <12115@goofy.megatest.UUCP> Sender: news@cl.cam.ac.uk Reply-To: cet1@cl.cam.ac.uk (C.E. Thompson) Organization: U of Cambridge Comp Lab, UK Lines: 58 In article <12115@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes: >From article <981@m1.cs.man.ac.uk>, by chl@cs.man.ac.uk (Charles Lindsey): >... >> >> I tried to get the PASCAL standardizers to get it right, but although they >> admitted the merit of my case, they got cold feet because, in the meantime, >> all hardware was now being built the way languages were now defining it. >> > >I too haggled with the Pascal standardizers, but I was under the impression >that we WON. I just now went back to an old draft copy, and to >_Standard_Pascal_ by Doug Cooper, and I discover that dammit, they >only did MOD right, not DIV. > >@#$%^&!!! > >MOD is stipulated to be correct, but -- get this! -- DIV is stipulated >to be wrong! You can't even do it right if you want to. Not unless you >want to (shudder) violate the standard. Oooooo. They say, > > abs(i) - abs(j) < abs((i div j)*j) <= abs(i) > >There's them damnable abses again. What the **** has abs got to do with >anything? Abses in definitions translate into tests for > 0 at runtime. >Who needs the agravation? > >And then they confess, 'NOTE: Only for i >=0 and j > 0 does the relation >(i div j) * j + i mod j = i hold.' (Slight correction to quotation made there) Why the big suprise? I thought that this <%rudeword> in Pascal was NOTORIOUS. And you have had eight years to find out about it :-) If I have it right, the critical change happened between the 3rd and 5th working drafts (i.e. between Oct 1978 and Nov 1979). In the 3rd, i div j was defined for i>=0, j>0 to be what everyone would expect; to be an error if j=0, and to be 'implementation defined' in other cases; however i mod j was defined to be i - j*(i div j) (by implication, for all i,j). By the 5th these definitions, which at least allow the 'right' implementation, had been replaced by the mess that made it into the 1982 ISO standard. > > *** > >Just now I did a little experimenting. On Sun-3, release 4.3. In both C >and Pascal, division is correct, but mod is wrong. > >In other words, they have it exactly backwards from the ANSI Pascal >Standard. Not right mathematically. Not right according to the standard. >You got to wonder, how come? The *ANSI* standard... the fact that the ANSI standard is not the same as the ISO standard is another <%rudeword>. Luckily, it doesn't affect the div/mod discussion. Chris Thompson JANET: cet1@uk.ac.cam.phx Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk