Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 20793 invoked from network); 10 Sep 2010 20:56:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Sep 2010 20:56:09 -0000 Received: (qmail 16799 invoked by uid 500); 10 Sep 2010 20:56:08 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 16696 invoked by uid 500); 10 Sep 2010 20:56:08 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 16688 invoked by uid 99); 10 Sep 2010 20:56:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Sep 2010 20:56:07 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [193.74.71.27] (HELO eir.is.scarlet.be) (193.74.71.27) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Sep 2010 20:55:59 +0000 Received: from mail.harfang.homelinux.org (ip-213-49-249-191.dsl.scarlet.be [213.49.249.191]) by eir.is.scarlet.be (8.14.2/8.14.2) with ESMTP id o8AKtaSh007078 for ; Fri, 10 Sep 2010 22:55:37 +0200 Received: from localhost (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 954DF617ED for ; Fri, 10 Sep 2010 22:55:36 +0200 (CEST) Received: from mail.harfang.homelinux.org ([192.168.20.11]) by localhost (mail.harfang.homelinux.org [192.168.20.11]) (amavisd-new, port 10024) with ESMTP id orCnr2B4U+kI for ; Fri, 10 Sep 2010 22:55:34 +0200 (CEST) Received: from dusk.harfang.homelinux.org (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 727B261778 for ; Fri, 10 Sep 2010 22:55:34 +0200 (CEST) Received: from eran by dusk.harfang.homelinux.org with local (Exim 4.71) (envelope-from ) id 1OuAdC-0002PB-5E for dev@commons.apache.org; Fri, 10 Sep 2010 22:55:34 +0200 Date: Fri, 10 Sep 2010 22:55:33 +0200 From: Gilles Sadowski To: dev@commons.apache.org Subject: Re: svn commit: r995035 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BrentOptimizer.java Message-ID: <20100910205533.GA10200@dusk.harfang.homelinux.org> Mail-Followup-To: dev@commons.apache.org References: <20100908125138.E4C0A23889DA@eris.apache.org> <4C87A27D.9070102@free.fr> <20100908153752.GN18739@dusk.harfang.homelinux.org> <4C87B1D9.3010705@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4C87B1D9.3010705@free.fr> X-Operating-System: Tiny Tux X-PGP-Key-Fingerprint: 53B9 972E C2E6 B93C BEAD 7092 09E6 AF46 51D0 5641 User-Agent: Mutt/1.5.20 (2009-06-14) X-DCC-scarlet.be-Metrics: eir 20001; Body=1 Fuz1=1 Fuz2=1 > > I don't know whether it is one of those rare cases. The algorithm > > description in ALGOL uses the "=" sign while the FORTRAN implementation (in > > the appendix) works around the problem by inversing the checks: > > It may be the case. There is a similar one in the Brent solver, the > semantic of the test is to check if we have just set one intermediate > value exactly to one of the bound or if it is a result of some > interpolation. > > Exact equality or inequality should be considered with the same care. In > many cases, they should be replaced by proximity checks. Proximity > checks need a threshold and it is very difficult to find a general one > (some people may well use numbers in the range of 1.0e-50 which is > perfectly computable in floating point). > > There is also one very special trick with doubles equality and > inequality: tests involving NaN always return false. So if for example x > is a NaN and y is a regular number (normal, subnormal or infinite), all > the following tests will return false, even the two last ones! > > x < y, x > y, x <= y, x >= y, x == y, x != y, x == x > > This implies that replacing (x == y) by !(x != y) is a safe replacement > only if there are no NaNs involved. > > However, I don't think the test here has been written with NaNs in mind, > so I guess it really is a check for interpolation or no interpolation. I > did not check the algorithm, though. I don't think so either. With the current change, the meaning is as close to "==" as possible since only two adjacent floating point numbers are considered equal by method "equals" from "MathUtils". So if checkstyle is happy with that, we could leave so without much risk, I think. Gilles > >>> - } else if (fu <= fv || v == x || v == w) { > >>> + } else if (fu <= fv || > >>> + MathUtils.equals(v, x) || > >>> + MathUtils.equals(v, w)) { > >>> v = u; > >>> fv = fu; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org