Path: csiph.com!1.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Michael Jung Newsgroups: comp.lang.java.programmer Subject: Re: double == double Date: Sat, 15 Oct 2016 14:04:35 +0200 Organization: albasani.net Lines: 24 Message-ID: <87zim5es30.fsf@golem.phantasia.org> References: <8737k0qd38.fsf@golem.phantasia.org> Mime-Version: 1.0 Content-Type: text/plain X-Trace: news.albasani.net t/yFJpXJFMIehSSH18uNrbG3I+KyuFLPoks9qY2hf3VDMMhkpAVGhPjWNubMfcvWhsxcnAE7cViWUA+hXBhg+7rxB/wzBQB+CkGEXwrd9asf/Dv87V+Ba4UvZKmT7VUF NNTP-Posting-Date: Sat, 15 Oct 2016 12:04:35 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="MWgPGf9+pybtwjfA3kaA4KozPGYhIthcFGPNA1uqBj8l3JACU0zNXtxNjh0N/0WGO5E7NrEt4RvKKE2DSvQp5Hq8W4mzWVTVHBplbIl+5utY4KPLoTC/2As587kOwhFZ"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:71GZX1oiYTOZlbiK5e2eit4/PWI= sha1:gFMxFYpYbks4X4h9qqs1dMgJ6pg= Xref: csiph.com comp.lang.java.programmer:35763 Michael Jung writes: > Eric Sosman writes: >> On 10/12/2016 8:15 AM, Stefan Ram wrote: [...] >> The problem with comparing double or float values for equality >> (or inequality) isn't the values themselves, but their "provenance." >> Calculations that yield identical results when performed with real >> numbers and their infinite precision may yield different outcomes >> when finite-precision floating-point values are used instead. We >> know, for example, that `ln xy = ln x + ln y' for all positive x,y, >> yet we cannot rely on `Math.log(x*y) == Math.log(x) + Math.log(y)'. >> A rearrangement that appears innocuous can produce a result that is >> slightly different (sometimes more than "slightly!") from that of the >> original, and it's no simple matter to say which, if either, is >> "right." [...] More pointedly: don't use "==", when doing arithmetic. One of the applications of using "==" on doubles may be when they are used as version numbers such as modelling those of (La)TeX in Java. (This "argument" does not apply to +0 and -0, though.) Michael