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 6B5C07803 for ; Tue, 6 Sep 2011 09:31:26 +0000 (UTC) Received: (qmail 74377 invoked by uid 500); 6 Sep 2011 09:31:10 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 73172 invoked by uid 500); 6 Sep 2011 09:30:49 -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 73076 invoked by uid 99); 6 Sep 2011 09:30:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 06 Sep 2011 09:30:36 +0000 X-ASF-Spam-Status: No, hits=-2000.5 required=5.0 tests=ALL_TRUSTED,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; Tue, 06 Sep 2011 09:30:33 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id A126482214 for ; Tue, 6 Sep 2011 09:30:11 +0000 (UTC) Date: Tue, 6 Sep 2011 09:30:11 +0000 (UTC) From: "Yannick TANGUY (JIRA)" To: issues@commons.apache.org Message-ID: <1549386014.19677.1315301411656.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Created] (MATH-658) Dead code in FastMath.pow(double, double) and some improvement in test coverage MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org Dead code in FastMath.pow(double, double) and some improvement in test coverage ------------------------------------------------------------------------------- Key: MATH-658 URL: https://issues.apache.org/jira/browse/MATH-658 Project: Commons Math Issue Type: Improvement Reporter: Yannick TANGUY Priority: Minor Fix For: 3.0 This issue concerns the FastMath class and its test class. I don't know how to attach source code to an issue : sorry if it's not easy to read... (1) In the double pow(double, double) function, there are 2 identical "if" blocks. The second one can be suppressed. if (y < 0 && y == yi && (yi & 1) == 1) { return Double.NEGATIVE_INFINITY; } // this block is never used -> to be suppressed if (y < 0 && y == yi && (yi & 1) == 1) { return -0.0; } if (y > 0 && y == yi && (yi & 1) == 1) { return -0.0; } (2) To obtain better code coverage, we added some tests case in FastMathTest.java : /** * Added test for log1p */ @Test public void testLog1pSpecialCases() { double x; x = FastMath.log1p(-1.0); if (x != Double.NEGATIVE_INFINITY) throw new RuntimeException("Log1p of -1 should be -infinity"); } public void testPowSpecialCases() { // [ ... ] // Added tests for a 100% coverage x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN); if (x == x) throw new RuntimeException("pow(+Inf, NaN) should be NaN"); x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN); if (x == x) throw new RuntimeException("pow(+Inf, NaN) should be NaN"); x = FastMath.pow(1.0, Double.POSITIVE_INFINITY); if (x == x) throw new RuntimeException("pow(1.0, +Inf) should be NaN"); x = FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN); if (x == x) throw new RuntimeException("pow(-Inf, NaN) should be NaN"); x = FastMath.pow(Double.NEGATIVE_INFINITY, -1.0); if (x != -0.0) throw new RuntimeException("pow(-Inf, -1.0) should be 0.0"); x = FastMath.pow(Double.NEGATIVE_INFINITY, -2.0); if (x != 0.0) throw new RuntimeException("pow(-Inf, -2.0) should be 0.0"); x = FastMath.pow(Double.NEGATIVE_INFINITY, 1.0); if (x != Double.NEGATIVE_INFINITY) throw new RuntimeException("pow(-Inf, 1.0) should be -Inf"); x = FastMath.pow(Double.NEGATIVE_INFINITY, 2.0); if (x != Double.POSITIVE_INFINITY) throw new RuntimeException("pow(-Inf, 2.0) should be +Inf"); x = FastMath.pow(1.0, Double.NEGATIVE_INFINITY); if (x == x) throw new RuntimeException("pow(1.0, -Inf) should be NaN"); } /** * Added tests for a 100% coverage of acos(). */ @Test public void testAcosSpecialCases() { double x; x = FastMath.acos(Double.NaN); if (x == x) throw new RuntimeException("acos(NaN) should NaN"); x = FastMath.acos(-1.1); if (x == x) throw new RuntimeException("acos(-1.1) should NaN"); x = FastMath.acos(1.1); if (x == x) throw new RuntimeException("acos(-1.1) should NaN"); assertEquals(FastMath.acos(-1.0), FastMath.PI, Double.MIN_VALUE); assertEquals(FastMath.acos(1.0), 0.0, Double.MIN_VALUE); assertEquals(FastMath.acos(0.0), FastMath.PI / 2.0, Double.MIN_VALUE); } /** * Added tests for a 100% coverage of asin(). */ @Test public void testAsinSpecialCases() { double x; x = FastMath.asin(Double.NaN); if (x == x) throw new RuntimeException("asin(NaN) should NaN"); x = FastMath.asin(-1.1); if (x == x) throw new RuntimeException("asin(-1.1) should NaN"); x = FastMath.asin(1.1); if (x == x) throw new RuntimeException("asin(-1.1) should NaN"); assertEquals(FastMath.asin(1.0), FastMath.PI / 2.0, Double.MIN_VALUE); assertEquals(FastMath.asin(-1.0), -FastMath.PI / 2.0, Double.MIN_VALUE); assertEquals(FastMath.asin(0.0), 0.0, Double.MIN_VALUE); } -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira