From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3b4bed4f74b8ac49 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: GNAT messages and the not operator (pitfall alert!) Date: 1996/10/26 Message-ID: <01bbc32d$02339460$038371a5@dhoossr.iquest.com>#1/1 X-Deja-AN: 192203942 distribution: world references: <1996Oct25.103321.1@corning.com> content-type: text/plain; charset=ISO-8859-1 organization: DBH Enterprises, Inc. mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-10-26T00:00:00+00:00 List-Id: whiting_ms@corning.com (Matt Whiting) wrote in article <1996Oct25.103321.1@corning.com>... > In article , dewar@merv.cs.nyu.edu (Robert Dewar) writes: > > Here is another pitfall, pretty horrible if it hits, but fortunately rare. > > Ask an Ada expert what is the value of > > > > -5 mod 3 > > > > Almost anyone (the better they know Ada, the more likely they are to make > > this mistake) will strain to remember the table in the RM that talks about > > negative mods, and, if they remember it right, come up with the answer of 1. > > But Ada has VERY odd precedence rules which mean that the default > > parenthesiztion of this expression is -(5 mod 3). The only person I > > ever knew to get this right (and remember this is under conditions they > > know they are being asked to answer a trick question) was Robert Eachus > > (both Jean and Tuck got this wrong originally, and so did I :-) > > I'm really confused now. How does -(5 mod 3) yield 1? I thought 5 mod 3 would > evaluate to 2 and then the unary minus would yield -2. Will someone provide a > play-by-play evaluation sequence for this expression? > > Matt > Hi Matt, I think the problem is that you didn't read Robert's English very carefully. It might have been better had he said "....and, if they remember it right, come up with the (wrong) answer of 1." In other words, (-5) mod 3 = 1, and -(5 mod 3) = 2 -- David C. Hoos, Sr., http://www.dbhwww.com http://www.ada95.com