Return-Path:
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: (qmail 82107 invoked from network); 5 Jul 2009 12:53:29 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3)
by minotaur.apache.org with SMTP; 5 Jul 2009 12:53:29 -0000
Received: (qmail 72949 invoked by uid 500); 5 Jul 2009 12:53:39 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 72869 invoked by uid 500); 5 Jul 2009 12:53:39 -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 72860 invoked by uid 99); 5 Jul 2009 12:53:39 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jul 2009 12:53:39 +0000
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, 05 Jul 2009 12:53:35 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id 635ED23888D9; Sun, 5 Jul 2009 12:53:14 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r791237 - in /commons/proper/math/trunk: pom.xml
src/java/org/apache/commons/math/complex/Complex.java
src/site/xdoc/changes.xml
src/test/org/apache/commons/math/complex/ComplexTest.java
Date: Sun, 05 Jul 2009 12:53:14 -0000
To: commits@commons.apache.org
From: luc@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20090705125314.635ED23888D9@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: luc
Date: Sun Jul 5 12:53:13 2009
New Revision: 791237
URL: http://svn.apache.org/viewvc?rev=791237&view=rev
Log:
added scalar multiply to the Complex class
JIRA: MATH-277
Modified:
commons/proper/math/trunk/pom.xml
commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexTest.java
Modified: commons/proper/math/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/pom.xml?rev=791237&r1=791236&r2=791237&view=diff
==============================================================================
--- commons/proper/math/trunk/pom.xml (original)
+++ commons/proper/math/trunk/pom.xml Sun Jul 5 12:53:13 2009
@@ -103,6 +103,9 @@
C. Scott Ananian
+ Mark Anderson
+
+
Rémi Arntzen
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java?rev=791237&r1=791236&r2=791237&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java Sun Jul 5 12:53:13 2009
@@ -387,6 +387,44 @@
}
/**
+ * Return the product of this complex number and the given scalar number.
+ *
+ * Implements preliminary checks for NaN and infinity followed by
+ * the definitional formula:
+ *
+ * c(a + bi) = (ca) + (cb)i
+ *
+ *
+ *
+ * Returns {@link #NaN} if either this or rhs
has one or more
+ * NaN parts.
+ *
+ * Returns {@link #INF} if neither this nor rhs
has one or more
+ * NaN parts and if either this or rhs
has one or more
+ * infinite parts (same result is returned regardless of the sign of the
+ * components).
+ *
+ *
+ * Returns finite values in components of the result per the
+ * definitional formula in all remaining cases.
+ *
+ *
+ * @param rhs the scalar number
+ * @return the complex number product
+ */
+ public Complex multiply(double rhs) {
+ if (isNaN() || Double.isNaN(rhs)) {
+ return NaN;
+ }
+ if (Double.isInfinite(real) || Double.isInfinite(imaginary) ||
+ Double.isInfinite(rhs)) {
+ // we don't use Complex.isInfinite() to avoid testing for NaN again
+ return INF;
+ }
+ return createComplex(real * rhs, imaginary * rhs);
+ }
+
+ /**
* Return the additive inverse of this complex number.
*
* Returns Complex.NaN
if either real or imaginary
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=791237&r1=791236&r2=791237&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Jul 5 12:53:13 2009
@@ -45,6 +45,9 @@
Added robust locally weighted regression (Loess).
+
+ Added a scalar multiply to the Complex class
+
Added curve fitting with a general case and two specific cases (polynomial and harmonic).
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexTest.java?rev=791237&r1=791236&r2=791237&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/complex/ComplexTest.java Sun Jul 5 12:53:13 2009
@@ -219,6 +219,31 @@
assertTrue(Double.isNaN(w.getImaginary()));
}
+ public void testScalarMultiply() {
+ Complex x = new Complex(3.0, 4.0);
+ double y = 2.0;
+ Complex z = x.multiply(y);
+ assertEquals(6.0, z.getReal(), 1.0e-5);
+ assertEquals(8.0, z.getImaginary(), 1.0e-5);
+ }
+
+ public void testScalarMultiplyNaN() {
+ Complex x = new Complex(3.0, 4.0);
+ Complex z = x.multiply(Double.NaN);
+ assertTrue(z.isNaN());
+ }
+
+ public void testScalarMultiplyInf() {
+ Complex z = new Complex(1,1);
+ Complex w = z.multiply(Double.POSITIVE_INFINITY);
+ assertEquals(w.getReal(), inf, 0);
+ assertEquals(w.getImaginary(), inf, 0);
+
+ w = z.multiply(Double.NEGATIVE_INFINITY);
+ assertEquals(w.getReal(), inf, 0);
+ assertEquals(w.getImaginary(), inf, 0);
+ }
+
public void testNegate() {
Complex x = new Complex(3.0, 4.0);
Complex z = x.negate();