Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!oliveb!sun!rushforth!kcr From: kcr%rushforth@Sun.COM (Kevin Rushforth) Newsgroups: comp.sys.mac.programmer Subject: Re: LSC arithmetic problem Message-ID: <100903@sun.Eng.Sun.COM> Date: 25 Apr 89 01:06:04 GMT References: <1837@etive.ed.ac.uk> Sender: news@sun.Eng.Sun.COM Reply-To: kcr@sun.UUCP (Kevin Rushforth) Organization: Sun Microsystems, Mountain View Lines: 25 In article <1837@etive.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes: >Well, perhaps not a problem, but certainly a "gotcha". The following >declaration: > > long L = (1<<16) + 1; > >results in L being (long) 1. Presumably LSC does its intermediate arithmetic >in 16-bit ints K&R and the proposed ANSI standard both say that integer arithmetic is done in "int" precision (whatever that may be for your machine) unless one or more of the operands is of type long. On a MAC, the LSC compiler uses 16-bit ints (don't know about the MPW compiler). To ensure that the calculations are done in "long" precision (i.e. 32-bit arithmetic), you can do what you suggested (cast the constant(s) to long) or more simply declare the constants as long in the first place: long L = (1L << 16) + 1L; -- Kevin C. Rushforth | "If winning is not important, Sun Microsystems | then commander, why keep score?" | - Lt. Worf ARPA: kcr@sun.com | UUCP: !sun!kcr |