Xref: utzoo sci.math:2871 comp.lang.modula2:652 Path: utzoo!mnetor!uunet!mcvax!cernvax!ethz!forty2!claudio From: claudio@forty2.UUCP (Claudio Nieder) Newsgroups: sci.math,comp.lang.modula2 Subject: Re: MOD in Modula-2 flawed (was Re: perpetual calendar (also day of week)) Message-ID: <147@forty2.UUCP> Date: 17 Feb 88 12:04:42 GMT References: <8802101656.AA08424@decwrl.dec.com> <6413@j.cc.purdue.edu> <4057@xanth.cs.odu.edu> Reply-To: claudio@forty2.UUCP (Claudio Nieder) Organization: Exp. Physics University Zuerich Lines: 40 Keywords: munged In article <4057@xanth.cs.odu.edu> kent@xanth.UUCP (Kent Paul Dolan) writes: > ... >It appears Wirth was too seduced by the beauty of the "identity" x = >modulus * ( x DIV modulus ) + ( x MOD modulus ) [which is how he >defines MOD]... I think the above mentioned "identity" is quite right, the problem is how you define x DIV modulus. In PIM3 Wirth defines: "Integer division is denoted by DIV and truncates the quotient. For example ... -15 DIV 4= -3" but there seems some room for changes. On his compiler for the CERES (a NS32032 based Workstation built at the ETH) he redefined that, thus now -15 DIV 4=-4 and -15 MOD 4=1 I have read in some paper that dealt with the proposed BSI Modula-2 standard that Wirth suggested/considered/approved/wasn't against the following solution (perhaps somebody who has acces to the BSI papers may tell more about that): -15 DIV 4=-4, -15 MOD 4=1 -15 / 4=-3, -15 REM 4=-3 On CERES DIV, MOD and "/" are implemented as mentioned above while "REM" is not implemented. The way how you actually implement it may also be influenced by the underlying Processor. On the NS32032 both definitions of DIV and MOD exist, thus it is quite easy to provide both. The MC68000 Processor provides only the "/",REM variant. Therefor on the M2Amiga compiler, which implements both variants, "/" and REM simply use the processors DIVS instruction while DIV and MOD generate more complex code. claudio