From commits-return-72088-archive-asf-public=cust-asf.ponee.io@commons.apache.org Mon Feb 3 16:59:49 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 02193180647 for ; Mon, 3 Feb 2020 17:59:48 +0100 (CET) Received: (qmail 77987 invoked by uid 500); 3 Feb 2020 16:59:47 -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 77964 invoked by uid 99); 3 Feb 2020 16:59:47 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2020 16:59:47 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 152EB8B691; Mon, 3 Feb 2020 16:59:46 +0000 (UTC) Date: Mon, 03 Feb 2020 16:59:47 +0000 To: "commits@commons.apache.org" Subject: [commons-numbers] 01/02: Move the check for a finite value known to be positive to a method. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: aherbert@apache.org In-Reply-To: <158074918665.24682.11546171041989050546@gitbox.apache.org> References: <158074918665.24682.11546171041989050546@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: commons-numbers X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 25f71b03fc7f730eb7239376dbd4921aea336c17 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20200203165947.152EB8B691@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-numbers.git commit 25f71b03fc7f730eb7239376dbd4921aea336c17 Author: aherbert AuthorDate: Mon Feb 3 16:58:21 2020 +0000 Move the check for a finite value known to be positive to a method. --- .../java/org/apache/commons/numbers/complex/Complex.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java index 5a322c3..33e8a4d 100644 --- a/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java +++ b/commons-numbers-complex/src/main/java/org/apache/commons/numbers/complex/Complex.java @@ -2995,8 +2995,7 @@ public final class Complex implements Serializable { final double x = Math.abs(real); // Handle inf or nan. - // Deliberate logic inversion using x to match !Double.isFinite(x) knowing x is absolute. - if (!(x <= Double.MAX_VALUE) || !Double.isFinite(imaginary)) { + if (!isPosFinite(x) || !Double.isFinite(imaginary)) { if (isPosInfinite(x)) { if (Double.isFinite(imaginary)) { // The sign is copied from sin(2y) @@ -3222,6 +3221,18 @@ public final class Complex implements Serializable { } /** + * Check that an absolute value is finite. Used to replace {@link Double#isFinite()} + * when the input value is known to be positive (i.e. in the case where it has been + * set using {@link Math#abs(double)}). + * + * @param d Value. + * @return {@code true} if {@code d} is +finite. + */ + private static boolean isPosFinite(double d) { + return d <= Double.MAX_VALUE; + } + + /** * Create a complex number given the real and imaginary parts, then multiply by {@code -i}. * This is used in functions that implement trigonomic identities. It is the functional * equivalent of: