[Openmcl-devel] Negative number to positive whole-number float exponent
gb at clozure.com
Sat Apr 4 20:48:20 EDT 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
> 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:
> (expt -1.0d0 1.0d0)
CL-USER 1 > (expt -1.0d0 1.0d0)
* (expt -1.0d0 1.0d0)
CL-USER(1): (expt -1.0d0 1.0d0)
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)
> Thank you.
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
More information about the Openmcl-devel