Path: utzoo!attcan!uunet!husc6!rutgers!bellcore!decvax!spray!anson From: anson@spray.CalComp.COM (Ed Anson) Newsgroups: comp.sys.mac.programmer Subject: Re: Float to integer conversion problem in LSC 3.0? Keywords: Lightspeed, LSC, conversion Message-ID: <2403@spray.CalComp.COM> Date: 8 Aug 88 14:39:33 GMT References: <5813@batcomputer.tn.cornell.edu> Reply-To: anson@spray.UUCP (Ed Anson) Organization: CalComp, A Lockheed Company, Hudson, NH, USA Lines: 20 In article <5813@batcomputer.tn.cornell.edu> eacj@tcgould.tn.cornell.edu (Julian Vrieslander) writes: > > 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. Because of the differences between binary and decimal notation, the value 12.6 cannot be represented exactly in floating point format. My guess is that 12.6 gets converted to something just a hair lower than 12.6, which will always give the result described. When converting from floating point to integer, I generally round the value, rather than simply truncate. That approach saves a lot of grief. -- ===================================================================== Ed Anson, Calcomp Display Products Division, Hudson NH 03051 (603) 885-8712, anson@elrond.CalComp.COM