From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public From: "Bob Binder (remove .mapson to email)" Subject: Re: floating point comparison Date: 1997/08/05 Message-ID: <01bca1a2$87d442a0$e1e989cc@gort>#1/1 X-Deja-AN: 262474404 Distribution: inet References: <01bc9dca$762b6000$e1e989cc@gort> <33E261F7.2EFB@mailgw.sanders.lockheed.com> <33E611E4.2E1A@pseserv3.fw.hac.com> Organization: RBSC Corporation Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-08-05T00:00:00+00:00 List-Id: W. Wesley Groleau x4923 wrote in article <33E611E4.2E1A@pseserv3.fw.hac.com>... > > >> x, y float; > > > > >> x = 1.0; > > >> y = (x/10.0)*10.0; > > >> if x == y { > > >> // not likely } > > >> else { > > >> // more likely > > >> }; > > >Although I am reading this in comp.lang.ada, the suggestion to try a > > >simple example like this in C piqued my interest. > > You lucked out due to IEEE rounding to nearest. > [snip] > > On the other hand, try (1.0/49.0)*49.0. > > 49 "works" in GNAT. The following gets eight 'no' and 92 'yes' : > > with Ada.Text_IO; > procedure FP_Test is > ONE : constant Float := 1.0; > begin > for I in 1 .. 100 loop > if ONE = ( ONE / Float(I) ) * Float(I) then > Ada.Text_IO.Put_Line ( Integer'Image(I) & ": YES !!" ); > else > Ada.Text_IO.Put_Line ( Integer'Image(I) & ": no...." ); > end if; > end loop; > end FP_Test; > Way to go Wes! ______________________________________________________________________________ Bob Binder http://www.rbsc.com RBSC Corporation 312 214-3280 tel Software Engineering 3 First National Plaza 312 214-3110 fax Process Improvement Suite 1400 rbinder@rbsc.mapson.com (remove .mapson to mail) Chicago, IL 60602-4205