Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13658
| From | Miles Bader <miles@gnu.org> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: comparing floating point numbers |
| Date | 2012-01-30 11:48 +0900 |
| Message-ID | <87sjixrjlc.fsf@catnip.gol.com> (permalink) |
| References | <jg44ad$fti$1@news.icm.edu.pl> <4f25ad65$0$6577$9b4e6d93@newsspool3.arcor-online.net> <jg4io7$5o2$1@speranza.aioe.org> |
BCFD36 <bcfd36@cruzio.com> writes: >>> if (b == 0.0 && (a == 0.25 || a == -0.75)) >> >> Comparing floating point numbers for equality is almost always a bug. >> Only singular values like 0.0 are usually safe. > > Agreed. And anyone who made it past the 1st Intro to CS class would > know that. I've no idea of the Original Poster's background so I > wasn't going to speculate on his training. I'm pretty sure english is > a 2nd language for him so what he asked and what he meant to ask were > not quite the same. I can't fault someone for that. > > But, yes, comparing floats for equality is not a good thing. ... unless checking for the aforementioned "singular values", resulting from simple assignment rather than calculation, and known to have a representation that cannot suffer from precision loss etc. The latter _is_ perfectly fine, which is why, for instance, a simplistic compiler warning to complain about floating-point equality comparison isn't so useful... -miles -- Brain, n. An apparatus with which we think we think.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
comparing floating point numbers Adam Majewski <adammaj1@o2.pl> - 2012-01-29 19:48 +0100
Re: comparing floating point numbers BCFD36 <bcfd36@cruzio.com> - 2012-01-29 11:02 -0800
Re: comparing floating point numbers "MikeWhy" <boat042-nospam@yahoo.com> - 2012-01-29 13:25 -0600
Re: comparing floating point numbers "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-01-29 20:40 +0100
Re: comparing floating point numbers Adam Majewski <adammaj1@o2.pl> - 2012-01-30 18:03 +0100
Re: comparing floating point numbers Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-01-29 21:34 +0100
Re: comparing floating point numbers BCFD36 <bcfd36@cruzio.com> - 2012-01-29 14:55 -0800
Re: comparing floating point numbers Miles Bader <miles@gnu.org> - 2012-01-30 11:48 +0900
Re: comparing floating point numbers Juha Nieminen <nospam@thanks.invalid> - 2012-01-30 14:53 +0000
Re: comparing floating point numbers scott@slp53.sl.home (Scott Lurndal) - 2012-01-30 17:22 +0000
Re: comparing floating point numbers Robert Wessel <robertwessel2@yahoo.com> - 2012-01-30 13:55 -0600
Re: comparing floating point numbers glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-02-13 01:56 +0000
Re: comparing floating point numbers LR <lruss@superlink.net> - 2012-01-29 18:30 -0500
Re: comparing floating point numbers Thomas Boell <tboell@domain.invalid> - 2012-01-30 16:29 +0100
Re: comparing floating point numbers Christian Gollwitzer <auriocus@gmx.de> - 2012-01-30 08:07 +0100
Re: comparing floating point numbers glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-02-13 01:59 +0000
Re: comparing floating point numbers Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-30 06:26 -0800
csiph-web