Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E06DDC1C for ; Thu, 20 Sep 2012 08:15:15 +0000 (UTC) Received: (qmail 99381 invoked by uid 500); 20 Sep 2012 08:15:15 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 98745 invoked by uid 500); 20 Sep 2012 08:15:09 -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 97749 invoked by uid 99); 20 Sep 2012 08:15:08 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Sep 2012 08:15:08 +0000 Date: Thu, 20 Sep 2012 19:15:07 +1100 (NCT) From: "Yannick TANGUY (JIRA)" To: issues@commons.apache.org Message-ID: <186753565.101386.1348128908045.JavaMail.jiratomcat@arcas> Subject: [jira] [Created] (MATH-866) New method to compute relative deviation between two floating numbers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 Yannick TANGUY created MATH-866: ----------------------------------- Summary: New method to compute relative deviation between two floating numbers Key: MATH-866 URL: https://issues.apache.org/jira/browse/MATH-866 Project: Commons Math Issue Type: Improvement Affects Versions: 3.1 Reporter: Yannick TANGUY A new method to compute a relative deviation would be very useful. In order to handle properly odd values (O+,0-,NaN,Infinity), we suggest to call first the classical equals() method (strict equality, using one ulp as a threshold) and then the relative tolerance. Here is the code we use : public static boolean equalsWithRelativeTolerance(final double x, final double y, final double eps) { // Initialisation boolean isEqual = false; // very close (including both equals 0.0) case if (equals(x, y)) { isEqual = true; } // common case else { // Relative difference computation final double absoluteMax = FastMath.max(FastMath.abs(x), FastMath.abs(y)); final double relativeDifference = FastMath.abs((x - y) / absoluteMax); //test if (relativeDifference < eps) { isEqual = true; } } return isEqual; } -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira