Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 47622 invoked from network); 16 Aug 2005 17:21:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Aug 2005 17:21:26 -0000 Received: (qmail 18478 invoked by uid 500); 16 Aug 2005 17:21:25 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 18088 invoked by uid 500); 16 Aug 2005 17:21:23 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 18068 invoked by uid 99); 16 Aug 2005 17:21:22 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Aug 2005 10:21:21 -0700 Received: by ajax.apache.org (Postfix, from userid 99) id 6980CE0; Tue, 16 Aug 2005 19:21:20 +0200 (CEST) From: bugzilla@apache.org To: commons-dev@jakarta.apache.org Subject: DO NOT REPLY [Bug 36205] New: - [math][patch] Update Complex.java X-Bugzilla-Reason: AssignedTo Message-Id: <20050816172120.6980CE0@ajax.apache.org> Date: Tue, 16 Aug 2005 19:21:20 +0200 (CEST) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG� RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND� INSERTED IN THE BUG DATABASE. http://issues.apache.org/bugzilla/show_bug.cgi?id=36205 Summary: [math][patch] Update Complex.java Product: Commons Version: unspecified Platform: All OS/Version: All Status: NEW Severity: normal Priority: P1 Component: Math AssignedTo: commons-dev@jakarta.apache.org ReportedBy: zxg_32@yahoo.com Index: Complex.java =================================================================== --- Complex.java (revision 233018) +++ Complex.java (working copy) @@ -66,7 +66,19 @@ if (isNaN()) { return Double.NaN; } - return Math.sqrt(squareSum()); + if (Math.abs(real) < Math.abs(imaginary)) { + if (imaginary == 0.0) { + return Math.abs(real); + } + double q = real / imaginary; + return (Math.abs(imaginary) * Math.sqrt(1 + q*q)); + } else { + if (real == 0.0) { + return Math.abs(imaginary); + } + double q = imaginary / real; + return (Math.abs(real) * Math.sqrt(1 + q*q)); + } } /** @@ -108,17 +120,29 @@ if (isNaN() || rhs.isNaN()) { return NaN; } - - if (Math.abs(rhs.getReal()) < Math.abs(rhs.getImaginary())) { - double q = rhs.getReal() / rhs.getImaginary(); - double d = (rhs.getReal() * q) + rhs.getImaginary(); - return new Complex(((real * q) + imaginary) / d, - ((imaginary * q) - real) / d); + + double c = rhs.getReal(); + double d = rhs.getImaginary(); + if (c == 0.0 && d == 0.0) { + throw new ArithmeticException("Error: division by zero."); + } + + if (Math.abs(c) < Math.abs(d)) { + if (d == 0.0) { + return new Complex(real/c, imaginary/c); + } + double q = c / d; + double denominator = c * q + d; + return new Complex((real * q + imaginary) / denominator, + (imaginary * q - real) / denominator); } else { - double q = rhs.getImaginary() / rhs.getReal(); - double d = (rhs.getImaginary() * q) + rhs.getReal(); - return new Complex(((imaginary * q) + real) / d, - (imaginary - (real * q)) / d); + if (c == 0.0) { + return new Complex(imaginary/d, -real/c); + } + double q = d / c; + double denominator = d * q + c; + return new Complex((imaginary * q + real) / denominator, + (imaginary - real * q) / denominator); } } -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org