Hi Will,

On Fri, Sep 21, 2012 at 12:08 AM,  <w...@ccs.neu.edu> wrote:
> Alex Shinn wrote:
>
>> One more thing - how was (expt 0 z) extended to
>> return 0 for complex z?  The approaches I've tried
>> would result in NaN, and indeed this seems to be
>> what most implementations return.
>
> You may be misinterpreting the R6RS.

I may indeed :)

> (expt 0 z) returns zero
> if the real part of z is positive.  If z is zero, then it's
> supposed to return zero.  If z is non-zero and its real part
> is zero or negative, then implementations are free to return
> whatever number object they like, or to raise an exception
> with condition type &implementation-restriction.

The question has to do with non-real z with positive
real part, i.e. (expt 0.0 c+di), c > 0, d != 0.  As a
simplification I can see how it would be useful to
simply define this to be 0, but it can't be derived as
far as I can see from the definition of complex
exponentiation, w^z = e^(z log(w)), because log(0)
is undefined.  Existing implementations also differ
in their results here.

-- 
Alex

> Implementation is straightforward.  Here is Larceny's code:
>
> (define (expt x y)
>
>   ; x is nonzero, and y is an exact natural number.
>
>   (define (e x y)
>     (cond ((= y 0)
>            1)
>           ((odd? y)
>            (* x (e x (- y 1))))
>           (else
>            (let ((v (e x (quotient y 2))))
>              (* v v)))))
>
>   (cond ((zero? x)
>          (let ((result (cond ((= y 0) 1)
>                              ((> (real-part y) 0) 0)
>                              (else +nan.0))))
>            (if (and (exact? x) (exact? y))
>                result
>                (exact->inexact result))))
>         ((and (exact? y) (integer? y))
>          (if (negative? y)
>              (/ (expt x (abs y)))
>              (e x y)))
>         (else
>          (exp (* y (log x))))))
>
> Will

_______________________________________________
r6rs-discuss mailing list
r6rs-discuss@lists.r6rs.org
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to