I just check on how sbcl handles this. The result was mixed, but
instructive as predicted.
Positive and negative infinity behave as expected.
** (/ 1 0.0)
#.SBEXT:SINGLEFLOATPOSITIVEINFINITY
* (/ 1 0.0)
*
***#.SBEXT:SINGLEFLOATNEGATIVEINFINITY
*
Square roots of negative infinity work as for option 3.
** (sqrt (/ 1 .0))
#C(0.0 #.SBEXT:SINGLEFLOATPOSITIVEINFINITY)
*
Fourth roots are reasonable as well.
** (sqrt (sqrt (/ 1 0.0)))
#C(#.SBEXT:SINGLEFLOATPOSITIVEINFINITY
#.SBEXT:SINGLEFLOATPOSITIVEINFINITY)
*
But, the exponentiation operator is inconsistent with these results and
behaves like option (1) (without documentation as far as I can tell).
** (expt (/ 1 .0) 0.25)
#.SBEXT:SINGLEFLOATPOSITIVEINFINITY
* (expt (/ 1 .0) 0.5)
#.SBEXT:SINGLEFLOATPOSITIVEINFINITY
*
On Fri, Jan 2, 2009 at 8:19 PM, Ted Dunning <ted.dunning@gmail.com> wrote:
> I think that (2) is the easiest for a user to understand. Obviously, the
> documentation aspect of (1) should be brought along.
>
> The behavior of Common Lisp is always instructive in these regards. The
> complex arithmetic was generally very well thought out.
>
> On Fri, Jan 2, 2009 at 7:14 PM, Phil Steitz <phil.steitz@gmail.com> wrote:
>
>> ... I noticed another thing. Behavior for complex numbers with NaN and
>>> infinite parts is, well, "interesting." It is consistent with what we do
>>> elsewhere in this class to just apply computational formulas and document
>>> behavior for infinite and NaN; but the current implementation is hard to
>>> document correctly and the results are a little strange for infinite values.
>>>
>>> I see three reasonable choices here, and am interested in others'
>>> opinions. Please select from the following or suggest something else.
>>>
>>> 1) Leave as is and just point out that the computational formula will
>>> behave strangely for infinite values.
>>>
>>> 2) return {Complex.NaN} or {Complex.INF} respectively when the number has
>>> a NaN or infinite part.
>>>
>>> 3) return {Complex.NaN} when either part is NaN; but for infinite values,
>>> compute the argument using getArgument (atan2), generate the arguments for
>>> the roots from this and select the real/im parts of the roots from {0, inf,
>>> inf} to match the argument (this will always be possible because atan2
>>> always returns a multiple of pi/4 for infinite arguments). For example, the
>>> 4th roots of real positive infinity would be {inf + 0i, 0 + infi, inf + 0i,
>>> 0 + infi}
>>>
>>> 2) is probably the most defensible mathematically; but 3) is closer to
>>> the spirit of C99x. Unfortunately, since our implementation of multiply is
>>> 2)like, 3) does not guarantee that nth roots actually solve the equation
>>> r^n = z.
>>>
>>

Ted Dunning, CTO
DeepDyve
4600 Bohannon Drive, Suite 220
Menlo Park, CA 94025
www.deepdyve.com
6503240110, ext. 738
8584140013 (m)
