Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 8862 invoked from network); 1 Mar 2009 22:21:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Mar 2009 22:21:53 -0000 Received: (qmail 87889 invoked by uid 500); 1 Mar 2009 22:21:52 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 87830 invoked by uid 500); 1 Mar 2009 22:21:52 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 87821 invoked by uid 99); 1 Mar 2009 22:21:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Mar 2009 14:21:52 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 01 Mar 2009 22:21:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5770D2388995; Sun, 1 Mar 2009 22:21:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r749139 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/util/MathUtils.java test/org/apache/commons/math/util/MathUtilsTest.java Date: Sun, 01 Mar 2009 22:21:23 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090301222123.5770D2388995@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Sun Mar 1 22:21:22 2009 New Revision: 749139 URL: http://svn.apache.org/viewvc?rev=749139&view=rev Log: added compareTo method with epsilon JIRA: MATH-247 Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=749139&r1=749138&r2=749139&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java Sun Mar 1 22:21:22 2009 @@ -348,6 +348,25 @@ } /** + * Compares two numbers given some amount of allowed error. + * + * @param x the first number + * @param y the second number + * @param eps the amount of error to allow when checking for equality + * @return
  • 0 if {@link #equals(double, double, double) equals(x, y, eps)}
  • + *
  • < 0 if !{@link #equals(double, double, double) equals(x, y, eps)} && x < y
  • + *
  • > 0 if !{@link #equals(double, double, double) equals(x, y, eps)} && x > y
+ */ + public static int compareTo(double x, double y, double eps) { + if (equals(x, y, eps)) { + return 0; + } else if (x < y) { + return -1; + } + return 1; + } + + /** * Returns the * hyperbolic cosine of x. * Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java?rev=749139&r1=749138&r2=749139&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java (original) +++ commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java Sun Mar 1 22:21:22 2009 @@ -305,6 +305,12 @@ .isInfinite(x)); } + public void testCompareTo() { + assertEquals(0, MathUtils.compareTo(152.33, 152.32, .011)); + assertTrue(MathUtils.compareTo(152.308, 152.32, .011) < 0); + assertTrue(MathUtils.compareTo(152.33, 152.318, .011) > 0); + } + public void testCosh() { double x = 3.0; double expected = 10.06766;