Path: utzoo!utdoe!generic!pnet91!ericmcg From: ericmcg@pnet91.cts.com (Eric Mcgillicuddy) Newsgroups: comp.sys.apple2 Subject: Re: Help with Floats in Hyper C Message-ID: <863@generic.UUCP> Date: 21 Jun 91 23:45:05 GMT Sender: root@generic.UUCP Organization: People-Net [pnet91], Etobicoke, ON Lines: 38 > float fahr, celsius; > int lower, upper, step; > > lower = 0; > upper = 300; > step = 20; > > fahr = lower; > while (fahr <= upper) { > celsius = (5.0/9.0) * (fahr-32); > printf("%3.0f %6.1f \n, fahr, celsius"); > fahr = fahr + step; > } >Bill Carss >bill@braille.uwo.ca The problem is that you are comparing apples to cats, although there may be some similarities from certain perspectives, these similarities may not be what you are interested in testing. Two things to note. Floats are stored in a different format from Ints. I think 0 is equivalent to both, but that is the end of all similarities. Certain compilers automatically coerce variables from one type to another, HyperC does not. The programmer must explicitly tell the compiler to test Ints as Floats doing the neccessary conversions beforehand to make the comparison meaning full. Casting lets the compiler know what you want to do. fahr = (float) lower; while (fahr <= (float) upper { do_stuff(); fahr = fahr + (float) step; } This should do the trick and is more portable (although still not good C code) than that in K&R's book. UUCP: bkj386!pnet91!ericmcg INET: ericmcg@pnet91.cts.com