[Openmcl-devel] Negative number to positive whole-number float exponent

Gary Byers gb at clozure.com
Sat Apr 4 17:48:20 PDT 2009

On Sat, 4 Apr 2009, Liam Healy wrote:

> A negative number to a positive whole-number exponent is real.

CLHS says (in the dictionary entry for EXP and EXPT):

"The result of expt can be a complex, even when neither argument is a
complex, if base-number is negative and power-number is not an
integer. The result is always the principal complex value."

Your example seems to be covered by this (1.0d0 is not an integer
...), and even the weakest reading of "can be" that I can come up with
seems to indicate that either a real or complex result is correct in
this case.

> In CCL 1.2, when the exponent is a float, there value is complex
> with a small imaginary part.  This is undesirable; can it be fixed?

Why is it undesirable, and why would changing it constitute "fixing" it ?
(There might be good answers to these questions; I don't know.)

A very quick unscientific survey:

clisp 2.46:

[1]> (expt -1.0d0 1.0d0)
#C(-1.0d0 0.0d0)

LW 5.1:

CL-USER 1 > (expt -1.0d0 1.0d0)
#C(-1.0D0 1.2246063538223773D-16)

sbcl 1.0.22

* (expt -1.0d0 1.0d0)


AllegroCL 8.1:

CL-USER(1): (expt -1.0d0 1.0d0)
#C(-1.0d0 1.2246467991473532d-16)

It's hard to see how code could reliably and portably predict whether
the result is real or complex in this case, since at least one implementation
seems to return a real result (and the weak reading of "... can be ..."
suggests that this is perfectly legal.)

> Welcome to Clozure Common Lisp Version 1.2-r10552  (LinuxX8664)!
> ? (expt -1.0d0 1.0d0)
> #C(-1.0D0 1.2246467991473532D-16)
> ? (expt -1.0d0 1)
> -1.0D0
> Thank you.
> Liam
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list