Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Using Enumerated Types as Array Indexes Date: Thu, 18 Aug 2011 08:22:51 -0700 Organization: A noiseless patient Spider Lines: 16 Message-ID: References: <4e4b0d81$0$314$14726298@news.sunsite.dk> <4e4b1fe4$0$314$14726298@news.sunsite.dk> <6d418cda-dab3-43df-a9ec-293b43f2bbd8@glegroupsg2000goo.googlegroups.com> <9b2aglFuj7U1@mid.individual.net> <__-dnaxcSIRV-NHTnZ2dnUVZ_tOdnZ2d@earthlink.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 18 Aug 2011 15:23:00 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="32437"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gBmjgwZc3tWiLGnGoPG1Feuu8aq+SY+4=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <__-dnaxcSIRV-NHTnZ2dnUVZ_tOdnZ2d@earthlink.com> Cancel-Lock: sha1:OVA6jU/dj2U37g6KTbbU94iz+sE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7218 On 8/17/2011 6:07 PM, Patricia Shanahan wrote: > On 8/17/2011 4:48 PM, Andreas Leitgeb wrote: > ... >> Rather: arr[ (n%arr.length + arr.length) % arr.length ] > > I believe the root cause of the problem may have been thinking of % as a > modulo operator when it is really the remainder operator. Has any > thought been given to create Math.mod, for both int and long, with > implementation as above? I think I suggested a modulo operator %% some time ago. It would be handy. The derivation of the formula above escapes me.