Xref: utzoo sci.math:2841 comp.lang.modula2:644 Path: utzoo!mnetor!uunet!husc6!rutgers!rochester!PT.CS.CMU.EDU!sei!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: sci.math,comp.lang.modula2 Subject: Re: perpetual calendar (also day of week) Message-ID: <4179@aw.sei.cmu.edu> Date: 11 Feb 88 19:54:19 GMT References: <8802101656.AA08424@decwrl.dec.com> <6413@j.cc.purdue.edu> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (Robert Firth) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 28 In article <6413@j.cc.purdue.edu] ags@j.cc.purdue.edu.UUCP (Dave Seaman) writes: ]I don't have my copy of the Modula-2 standard available at the moment, but ]I believe that the definition of the MOD operator is similar to Pascal, ]where the standard says: ] ] A term of the form i mod j shall be an error if j is zero or ] negative, otherwise the value of i mod j shall be that value of ] (i-(k*j)) for integral k such that 0 <= i mod j < j. ] ]Therefore the correct value of (-1 MOD 7) is 6, not -1. In fact, I believe ]that in Modula-2 the result of the MOD operator is type CARDINAL and ]therefore cannot be negative. It sounds as if you may be stuck with a ]flawed implementation of Modula-2. Well, I DO have my copy of the reference document [PIM-2, 3rd ed], and it says no such thing. Section 8.2 says, in particular (a) the result of MOD is CARDINAL iff both operands are CARDINAL, and otherwise is INTEGER (b) x MOD y is the remainder after DIV, ie y*(x DIV y) + x MOD y = y (c) x DIV y is equal to the truncated quotient of x/y Therefore, the correct value of -1 MOD 7, at least according to Wirth, is -1.