Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!elroy!cit-vax!tybalt.caltech.edu!palmer From: palmer@tybalt.caltech.edu (David Palmer) Newsgroups: comp.sys.mac.programmer Subject: Re: Float to integer conversion problem in LSC 3.0? Keywords: Lightspeed, LSC, conversion Message-ID: <7665@cit-vax.Caltech.Edu> Date: 22 Aug 88 23:11:37 GMT References: <5813@batcomputer.tn.cornell.edu> <4933@teddy.UUCP> <1120@usfvax2.EDU> Sender: news@cit-vax.Caltech.Edu Reply-To: palmer@tybalt.caltech.edu.UUCP (David Palmer) Organization: California Institute of Technology Lines: 21 In article <1120@usfvax2.EDU> pollock@usfvax2.usf.edu.UUCP (Wayne Pollock) writes: > .... >, or use: > > n = d + 0.5; > >or some library routine if you want to round the number. Assuming the >default conversions will always work perfectly is just asking for >trouble. Use a library routine. n=d + 0.5 does not properly round d if d < 0 (or more precisely, d < -0.5). if d=-1.0, for instance, d+0.5 = -0.5 which is truncated to 0 when it is assigned to an integer variable. As long as you have thoroughly memorized K&R's white book, you should have no problem. David Palmer palmer@tybalt.caltech.edu ...rutgers!cit-vax!tybalt.caltech.edu!palmer "Flowers -- Just say NO!!" - Mighty Mouse