Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: double == double Date: Sat, 15 Oct 2016 10:46:08 -0400 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: <8737k0qd38.fsf@golem.phantasia.org> <87zim5es30.fsf@golem.phantasia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 15 Oct 2016 14:45:51 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="414bcd8b93082233ddd2be90cf792575"; logging-data="11795"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ji9orbdc6/2UbpfeYEGMl" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 In-Reply-To: Cancel-Lock: sha1:uR5OX2fjPOGpjuznu/uEJdPLnBc= Xref: csiph.com comp.lang.java.programmer:35767 On 10/15/2016 10:32 AM, Arne Vajhøj wrote: > On 10/15/2016 9:13 AM, Eric Sosman wrote: >> The scare quotes around "argument" seem appropriate. I attempted >> to explain the basis of the simplistic "Don't use ==" advice, hoping >> that an informed understanding would trump blind obedience to some >> mysterious rule. (Perhaps I was overly optimistic.) >> >> There are instances (admittedly not many) where floating-point == >> is reliable, appropriate, and "safe when used as directed." It seems >> to me that someone who can distinguish the safe from the unsafe cases >> will be a better programmer than someone who closes his mind and simply >> says "Never use ==, it's sometimes dangerous." > > But I would say that someone that even though a particular use of > double == is safe still consider alternatives that are less fragile > to break with future code modifications is a better software engineer > than those who reason that since they can see it is safe then all > future maintainers of the code will understand the issue and keep > it safe. Allow me to pose a related question: Do you ever use > with floating-point values? And do you ever use >= similarly? Now: How do you choose between > and >=, and why? I contend that someone who blindly obeys "Never use ==" will have no (rational) way to decide whether to use > as opposed to >=, since the only difference between them is the equality comparison he's pledged to avoid. That is, I contend there's no substitute for understanding. My own understanding is imperfect -- the field called Numerical Analysis is large, intricate, and subtle -- but nonetheless I feel that dicta like "Never" are, er, "Always" out of place. (Almost.) -- esosman@comcast-dot-net.invalid "Everybody must get stoned." Looks like the Swedish Academy was.