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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f43e6,c7637cfdf68e766 X-Google-Attributes: gidf43e6,public X-Google-Thread: 107079,c7637cfdf68e766 X-Google-Attributes: gid107079,public X-Google-Thread: 103376,c7637cfdf68e766 X-Google-Attributes: gid103376,public X-Google-Thread: f8362,c7637cfdf68e766 X-Google-Attributes: gidf8362,public X-Google-Thread: 109d8a,c7637cfdf68e766 X-Google-Attributes: gid109d8a,public From: "W. Wesley Groleau x4923" Subject: Re: floating point comparison Date: 1997/08/04 Message-ID: <33E611E4.2E1A@pseserv3.fw.hac.com>#1/1 X-Deja-AN: 262358772 Sender: usenet@most.fw.hac.com (News Administration) X-Nntp-Posting-Host: sparc02 References: <01bc9dca$762b6000$e1e989cc@gort> <33E261F7.2EFB@mailgw.sanders.lockheed.com> Organization: Hughes Defense Communications Newsgroups: comp.lang.ada,sci.math.num-analysis,comp.software-eng,comp.theory,sci.math Date: 1997-08-04T00:00:00+00:00 List-Id: > >> 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; -- ---------------------------------------------------------------------- Wes Groleau, Hughes Defense Communications, Fort Wayne, IN USA Senior Software Engineer - AFATDS Tool-smith Wanna-be Don't send advertisements to this domain unless asked! All disk space on fw.hac.com hosts belongs to either Hughes Defense Communications or the United States government. Using email to store YOUR advertising on them is trespassing! ----------------------------------------------------------------------