Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 99477 invoked from network); 23 Mar 2011 20:33:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Mar 2011 20:33:44 -0000 Received: (qmail 1295 invoked by uid 500); 23 Mar 2011 20:33:43 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 1072 invoked by uid 500); 23 Mar 2011 20:33:43 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 991 invoked by uid 99); 23 Mar 2011 20:33:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Mar 2011 20:33:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Mar 2011 20:33:42 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id C218A4A810 for ; Wed, 23 Mar 2011 20:33:05 +0000 (UTC) Date: Wed, 23 Mar 2011 20:33:05 +0000 (UTC) From: "Luc Maisonobe (JIRA)" To: issues@commons.apache.org Message-ID: <1920491664.7120.1300912385791.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <16635861.328361294875105667.JavaMail.jira@thor> Subject: [jira] [Closed] (MATH-471) MathUtils.equals(double, double) does not work properly for floats MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MATH-471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Luc Maisonobe closed MATH-471. ------------------------------ Closing issue as it was included in version 2.2, which has been released > MathUtils.equals(double, double) does not work properly for floats > ------------------------------------------------------------------ > > Key: MATH-471 > URL: https://issues.apache.org/jira/browse/MATH-471 > Project: Commons Math > Issue Type: Bug > Reporter: Sebb > Fix For: 2.2, 3.0 > > Attachments: Math471.patch > > > MathUtils.equals(double, double) does not work properly for floats. > There is no equals(float,float) so float parameters are automatically promoted to double. However, that is not necessarily appropriate, given that the ULP for a double is much smaller than the ULP for a float. > So for example: > {code} > double oneDouble = 1.0d; > assertTrue(MathUtils.equals(oneDouble, Double.longBitsToDouble(1 + Double.doubleToLongBits(oneDouble)))); // OK > float oneFloat = 1.0f; > assertTrue(MathUtils.equals(oneFloat, Float.intBitsToFloat(1 + Float.floatToIntBits(oneFloat)))); // FAILS > float f1 = 333.33334f; > double d1 = 333.33334d; > assertTrue(MathUtils.equals(d1, f1)); // FAILS > {code} > I think the equals() methods need to be duplicated with the appropriate changes for floats to avoid any problems with the promotion of floats. -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira