Path: utzoo!attcan!uunet!husc6!panda!teddy!set From: set@teddy.UUCP (Sean E. Trowbridge) Newsgroups: comp.sys.mac.programmer Subject: Re: Float to integer conversion problem in LSC 3.0? Keywords: Lightspeed, LSC, conversion Message-ID: <4933@teddy.UUCP> Date: 8 Aug 88 15:58:46 GMT References: <5813@batcomputer.tn.cornell.edu> Reply-To: set@teddy.UUCP (Sean E. Trowbridge) Organization: GenRad, Inc., Concord, Mass. Lines: 19 In article <5813@batcomputer.tn.cornell.edu> eacj@tcgould.tn.cornell.edu (Julian Vrieslander) writes: > > double d; > long m,n; > > m = 126.0; /* m becomes 126 */ > d = 12.6 * 10.0; /* d becomes 126 */ > n = d; /* n becomes 125 !! */ > >I cannot understand why n gets "rounded down" to 125. >Julian Vrieslander "Don't rush me... you'll get a rotten miracle." Floating point calculations are not always exact, since numbers are converted from decimal to binary and back. Since converting from a float to an int simply truncates the fractional part, I would imagine that 12.6 * 10.0 gives you 125.9999999, and assigning that value to an int (long) gives you 125. Sean Trowbridge