Xref: utzoo sci.math:2840 comp.lang.modula2:643 Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!decvax!purdue!i.cc.purdue.edu!j.cc.purdue.edu!ags From: ags@j.cc.purdue.edu (Dave Seaman) Newsgroups: sci.math,comp.lang.modula2 Subject: Re: perpetual calendar (also day of week) Message-ID: <6413@j.cc.purdue.edu> Date: 11 Feb 88 16:54:42 GMT References: <8802101656.AA08424@decwrl.dec.com> Reply-To: ags@j.cc.purdue.edu.UUCP (Dave Seaman) Organization: Purdue University Lines: 35 In article <8802101656.AA08424@decwrl.dec.com> fulton@navion.dec.com (10-Feb-1988 0957) writes: [ description of perpetual calendar formula omitted ] > I have been intrigued by the above formula, and I coded it up in > Logitech Modula-2 to try it out. It appears that there are some > cases where it doesn't work quite right. For instance: [ example leading to negative numbers omitted ] > Then you have -1 MOD 7 => -1, which does not equate to any of > the numbers assigned to Sunday thru Saturday, namely 0 thru 6. [ illustration of adding 7 to make result positive ] > I guess that this is an after-the-fact kludge; perhaps the > original formula could be changed so that the result doesn't > require "fixing" if it comes out negative. 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. -- Dave Seaman ags@j.cc.purdue.edu