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: Sun, 16 Oct 2016 08:37:18 -0400 Organization: A noiseless patient Spider Lines: 30 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: 7bit Injection-Date: Sun, 16 Oct 2016 12:37:02 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="f12cead17395777517f26fda90f51828"; logging-data="3821"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sxqCBvnW3nwhoW32MN+jH" 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:CxsD0Sg4rKsoedPEW1NFzHaD78s= Xref: csiph.com comp.lang.java.programmer:35781 On 10/15/2016 10:13 PM, 4ndre4 wrote: > On 15/10/2016 23:28, Eric Sosman wrote: > > [...] >> One problem is that String comparison is character-by-character, >> meaning that version "1.10" compares *less* than "1.9". > > That's true, but I was assuming that any comparison on versions would > not just be a mere string comparison, but take into account the specific > structure of the version number. For example, for a typical major.minor > version, I assume that the checker would split the two parts of the > version and compare them separately. ... and *still* get the wrong answer! String major = "1"; String minor = "10"; // OK if version is 1.9 or later: boolean okay = major.compareTo("1") > 0 || (major.compareTo("1") == 0 && minor.compareTo("9") >= 0); // Oops ... That is, plain String comparison is inadequate for checking complete version numbers, and also inadequate for checking the individual components of version tuples. As Arne suggests, something more sensitive to the structure and significance of the tuples is needed. -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM