Article View: alt.comp.lang.learn.c-c++
Article #67Re: Floating point equal to Integer Value ?
From: j
Date: Tue, 10 Jul 2001 15:58
Date: Tue, 10 Jul 2001 15:58
18 lines
2297 bytes
2297 bytes
> if(z==(float)x) Er, would this not mess things up? Floating the int *could* move off to nearest float (your 20 could become 19.999999999, etc) and that may or may not be == to z. Depending on what you want, you may want to be more precise: const float tol = 0.00001; float f, chek; int i; f = i = 20; chek = fabs(f-i); if(chek < tol) //then they are more or less equal. Tol could be the smallest representable float, but I would use 10 times this or more. etc.... I don't think this is an issue for small integers; it may not be an issue at all, not sure.
Technical Details
Message-ID:
<8AE1D314DFF53A06.395F957BE4BE057E.2DC06EA1B5271AF6@lp.airnews.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!howland.erols.net!news-out.nntp.airnews.net.MISMATCH!cabal10.airnews.net!news.airnews.net!cabal1.airnews.net!news-f.iadfw.net!usenetReferences:
<9iejot$4an2@news.emirates.net.ae> <3B4B62D4.FCE579AF@stcinc.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 108b44,dbd8a1f951d6b446 X-Google-Attributes: gid108b44,public X-Google-Thread: 108717,dbd8a1f951d6b446 X-Google-Attributes: gid108717,public X-Google-Thread: 109fba,dbd8a1f951d6b446 X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,dbd8a1f951d6b446 X-Google-Attributes: gid114592,public X-Google-Thread: 10b1c0,dbd8a1f951d6b446 X-Google-Attributes: gid10b1c0,public X-Google-Thread: 10d4ba,dbd8a1f951d6b446 X-Google-Attributes: gid10d4ba,public X-Google-ArrivalTime: 2001-07-10 13:53:30 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!howland.erols.net!news-out.nntp.airnews.net.MISMATCH!cabal10.airnews.net!news.airnews.net!cabal1.airnews.net!news-f.iadfw.net!usenet From: "j" <jbryson@accurate-automation.com> Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++,comp.lang.c++,comp.programming,comp.sys.lang.c++,csugrad.programming.c Subject: Re: Floating point equal to Integer Value ? Date: Tue, 10 Jul 2001 16:58:02 +0100 Organization: CDC Internet (using Airnews.net!) Lines: 22 Message-ID: <8AE1D314DFF53A06.395F957BE4BE057E.2DC06EA1B5271AF6@lp.airnews.net> X-Orig-Message-ID: <9ifple$o3v@library1.airnews.net> References: <9iejot$4an2@news.emirates.net.ae> <3B4B62D4.FCE579AF@stcinc.com> Abuse-Reports-To: abuse at cdc.net to report improper postings NNTP-Proxy-Relay: library1-aux.airnews.net NNTP-Posting-Time: Tue Jul 10 15:47:46 2001 NNTP-Posting-Host: !apL10eIDgptZhppAb0n (Encoded at Airnews!) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200