Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 42340 invoked from network); 11 Oct 2010 20:56:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Oct 2010 20:56:13 -0000 Received: (qmail 68747 invoked by uid 500); 11 Oct 2010 20:56:12 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 68674 invoked by uid 500); 11 Oct 2010 20:56:12 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 42533 invoked by uid 99); 11 Oct 2010 20:39:13 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gszpetkowski@gmail.com designates 209.85.214.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=Fn+JSHSB3Q7ukRqJGaA87YutM4GSp5xHSJszhUjMWbM=; b=R2iBbh8Vf/H/fgyqLBwaPTgB7efcouEWnIbV2b2WHL0gWcuUb0doIbFpdJEpQtU6Px uvCnd6Wm1PLPL0C84D+6YQSHkYAvpKbbnA+3QuqvG2+LyQGFzdvAL8d/ajzRi6UWd6Cr 0v2xDMVJscsf/i7KlY8tVVSCTSgOncU/T3AM8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=mYy+skWKnjpnKukKJPvQ3jyEwYwu8qRB/VUx5TJXlS/XRS0Q2Q4d+ys3db35ViAOJ/ LmwQPt7jCG79o87Nrop3/TQWYvffZRk277uEV6S4SszyEQOtTvIYFlqUKB7vBWS55XNC gT44wOqAKEl3PUCfzhlazKWDff/2WY99+oVs0= MIME-Version: 1.0 Date: Mon, 11 Oct 2010 22:38:45 +0200 Message-ID: Subject: [math] ComplexFormat parse for inverted complex number From: Grzegorz Szpetkowski To: user@commons.apache.org Content-Type: text/plain; charset=ISO-8859-1 I have a question how can I (easily) parse String like that: String sZ = "20i + 5.4"; On page http://commons.apache.org/math/userguide/complex.html I found example: ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i"); It's ok, but if I have inverted form like "20i + 5.4" then there is exception: "org.apache.commons.math.MathRuntimeException$9: unparseable complex number: "20i + 5.4". Pseudo-algorithm for proposed solution: 1) Parse first number 2) IF first number has imaginary character THEN remember that second number should be real number (without imaginary character) 3) Parse second number 4) IF second number has imaginary character and first had it too (look at 2)), THEN throw exception Thanks ! Greg --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org