Path: utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!jato!mars!kaleb From: kaleb@mars.jpl.nasa.gov (Kaleb Keithley) Newsgroups: comp.lang.c Subject: Re: Inherent imprecision of floating point variables Message-ID: <4186@jato.Jpl.Nasa.Gov> Date: 27 Jun 90 20:48:02 GMT References: <3300@crash.cts.com> <44436@ism780c.isc.com> Sender: news@jato.Jpl.Nasa.Gov Reply-To: kaleb@mars.UUCP (Kaleb Keithley) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 29 In article dylan@ibmpcug.CO.UK (Matthew Farwell) writes: -In article <44436@ism780c.isc.com> marv@ism780.UUCP (Marvin Rubenstein) writes: - -Consider the code segment:- - -main() -{ - float f; - - f = 0.0; - while (1) { - if (f == 10.0) break; - printf("%f\n", f); - f += 0.1; - } - printf("Stopped\n"); -} - -If its all to do with conversion routines, why doesn't this stop when f -reaches 10? - Because (10.0 - 0.1) + 0.1 will never be exactly equal to 10.0. kaleb@thyme.jpl.nasa.gov Jet Propeller Labs Kaleb Keithley "So that's what an invisible barrier looks like"