You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2005/10/30 22:05:48 UTC

[math] Complex operations and C99x compliance

I have updated the release plan
http://wiki.apache.org/jakarta-commons/math/1%2e1ReleasePlan
with some notes on basic complex arithmetic operations, comparing
current (1.0) behavior with Colt and R and making a recommendation for
1.1 in each case.

In some cases, the 1.1 recommendation differs from what would be
prescribed by the C99x Annex G standard.  That is because the
recommended behaviour would be relatively easy to document without
quoting from the C99x spec, which is a little complicated.  I have
made inquiries to ISO / ANSI on whether we can quote from the spec in
our javadoc and on this list. Until I get affirmative response, and
maybe even if I do, I think it is best to use the following "naive"
computing principle:

* Apply definitional formulas and return NaN in real or imaginary
parts when the normal java.lang.double arithmetic rules yield NaN
values.  Similarly for positive and negative infinity.

Unfortunately, * is a little tricky and in some places inefficient to
implement since the best computational formulas are not the same as
the definitional ones, so care has to be taken to ensure that NaNs and
INFs are correctly returned.

Input / patches welcome!  Feel free to add comments to the Wiki.  I
will summarize here and on the ticket once people have had a chance to
weigh in and I have heard back from ANSI/ISO on the spec issue.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Phil Steitz <ph...@gmail.com>.
Thanks!

Patches welcome :-)

To check out the MATH_1_1 branch, use
svn co https://svn.apache.org/repos/asf/jakarta/commons/proper/math/branches/MATH_1_1/


On 11/23/05, Elliotte Harold <el...@metalab.unc.edu> wrote:
> Phil Steitz wrote:
>
> > It would be great to have some more eyeballs verify that javadoc -
> > code - tests are all now in synch and the documentation is clear.
>
>
> A couple of notes:
>
> "A complex number analogous to Double.NaN" isn't quite descriptive
> enough. I'd suggest specifying that it's NaN + NaNi (if indeed that's
> the case)

Agreed.
>
> Delete the period from "Returns: the complex number sum." Same thing for
> a lot of other Returns clauses that are not complete sentences including
> getImaginary and getReal. See
> http://java.sun.com/j2se/javadoc/writingdoccomments/#styleguide
> particularly the section on @param and @return

Agreed there as well.
>
> Under divide "Throws NullPointerException if rhs is null." looks funny.
> Maybe an @throws is missing in the source code?

Probably should replace with @throws.  The point is to call attention
to the fact that null arguments are not allowed.
>
> Major: The isNaN spec seems contradictory. It says:
>
>      Returns true if this complex number is equal to the special
> Not-a-Number (NaN) value.
>
>      Returns:
>          true if either or both parts of this complex number take NaN
> values; false otherwise.
>
> The first sentence differs from the second. Also what does it means that
> a part of a complex number takes a NaN value? I suggest rewriting like this:
>
>      Returns true if either or both parts of this complex number is NaN;
> false otherwise.
>
>      Returns:
>          true if either or both parts of this complex number is NaN;
> false otherwise

Agreed, though given the way that equals is implemented, the
statements are not actually inconsistent.
>
> Under multiply, "infintite" should be "infinite". Same correction under
> subtract.

Good catch.  Thanks!

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Elliotte Harold <el...@metalab.unc.edu>.
Phil Steitz wrote:

> It would be great to have some more eyeballs verify that javadoc -
> code - tests are all now in synch and the documentation is clear. 


A couple of notes:

"A complex number analogous to Double.NaN" isn't quite descriptive 
enough. I'd suggest specifying that it's NaN + NaNi (if indeed that's 
the case)

Delete the period from "Returns: the complex number sum." Same thing for 
a lot of other Returns clauses that are not complete sentences including 
getImaginary and getReal. See 
http://java.sun.com/j2se/javadoc/writingdoccomments/#styleguide 
particularly the section on @param and @return

Under divide "Throws NullPointerException if rhs is null." looks funny. 
Maybe an @throws is missing in the source code?

Major: The isNaN spec seems contradictory. It says:

     Returns true if this complex number is equal to the special 
Not-a-Number (NaN) value.

     Returns:
         true if either or both parts of this complex number take NaN 
values; false otherwise.

The first sentence differs from the second. Also what does it means that 
a part of a complex number takes a NaN value? I suggest rewriting like this:

     Returns true if either or both parts of this complex number is NaN; 
false otherwise.

     Returns:
         true if either or both parts of this complex number is NaN; 
false otherwise

Under multiply, "infintite" should be "infinite". Same correction under 
subtract.

-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Phil Steitz <ph...@gmail.com>.
>
> The links to MathWorld in ComplexUtils should be set to replace the
> entire frameset.

+0

<snip>
>
> The pow function should specify that it returns NaN for 0 to the zeroth
> power.

+1
>
> tan, atan and possibly other functions can return infinity. This should
> be noted. e.g. tan(pi/2 + 0i) is infinite.

Yes, I guess the statment " Infinite values in real or imaginary parts
of the input may result in infinite or NaN values returned in parts of
the result." should be edited to also indicate that infinite values
resulting from applying the real functions specified in the computing
formulas are passed on unchanged in the result.

Thanks.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Elliotte Harold <el...@metalab.unc.edu>.
Phil Steitz wrote:

> The classes just changed are Complex and ComplexUtils; but any other
> javadoc errors that anyone can spot would be much appreciated.


The links to MathWorld in ComplexUtils should be set to replace the 
entire frameset.

Again the throws clauses look funny as if they were included directly in 
the description rather than in @throws doc comments

The pow function should specify that it returns NaN for 0 to the zeroth 
power.

tan, atan and possibly other functions can return infinity. This should 
be noted. e.g. tan(pi/2 + 0i) is infinite.

-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Phil Steitz <ph...@gmail.com>.
I added tests and documentation describing the 1.0 behavior and closed
the BZ ticket on this. I added docs specifying computing formulas and
describing how NaN and infinite values are handled.

It would be great to have some more eyeballs verify that javadoc -
code - tests are all now in synch and the documentation is clear.  I
have not yet merged these changes into trunk.  I will do this after
making a few more trivial updates and preparing RC4.  For now, the new
javadoc can be viewed here

http://people.apache.org/~psteitz/commons-math/apidocs/

The classes just changed are Complex and ComplexUtils; but any other
javadoc errors that anyone can spot would be much appreciated.

The current code and test cases are in the MATH_1_1 branch.
(https://svn.apache.org/repos/asf/jakarta/commons/proper/math/branches/MATH_1_1/).

Thanks in advance.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Phil Steitz <ph...@gmail.com>.
On 10/30/05, Elliotte Harold <el...@metalab.unc.edu> wrote:
> Phil Steitz wrote:
> > I have updated the release plan
> > http://wiki.apache.org/jakarta-commons/math/1%2e1ReleasePlan
> > with some notes on basic complex arithmetic operations, comparing
> > current (1.0) behavior with Colt and R and making a recommendation for
> > 1.1 in each case.
> >
>
> Would you remind those of us who came in late what "Colt" and "R" are?

Sorry!  "Colt" is a great Java scientific computation library
maintained by Wolfgang Hoschek at CERN.  See
http://hoschek.home.cern.ch/hoschek/colt/

R (http://www.r-project.org/) is a statistical programming language
that includes support for complex numbers.
>
>
> --
> Elliotte Rusty Harold  elharo@metalab.unc.edu
> XML in a Nutshell 3rd Edition Just Published!
> http://www.cafeconleche.org/books/xian3/
> http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [math] Complex operations and C99x compliance

Posted by Elliotte Harold <el...@metalab.unc.edu>.
Phil Steitz wrote:
> I have updated the release plan
> http://wiki.apache.org/jakarta-commons/math/1%2e1ReleasePlan
> with some notes on basic complex arithmetic operations, comparing
> current (1.0) behavior with Colt and R and making a recommendation for
> 1.1 in each case.
> 

Would you remind those of us who came in late what "Colt" and "R" are?


-- 
Elliotte Rusty Harold  elharo@metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org