In message <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
.EDU writes:
> [EMAIL PROTECTED] reports the following problem.
>
> Version: 1.4 Jan. 1998
> OS: Linux
> compiler: gcc
> configuration: --readline
> Expected behaviour:
> (-2)**2 yields 4
> Observed behaviour:
> (-2)**2 caused a program error.
> Transcript:
> Main> (-2)**2
> Program error: {primLogDouble (-2.0)}
>
> Code:
Why don't you use ^ instead of **?
(**) is defined in Prelude.hs as follows:
x ** y = exp (log x * y)
and 2 is of type Double by default. The above behavior is
thus corret in the sense that the Haskell Report is correct;
`log' for Double can not be applied to negaitive numbers.
If you need more general exponentiation, the following
may be appropriate:
rexp :: (Real a, Real b, RealFloat c) => a -> b -> c
x `rexp` y = realPart (cast x ** cast y)
where cast x = fromRatinal (toRational x)
which computes the exponentiation after casting the arguments
to complex values. The defintion of (**) is the same, but
log for `Complex a' can be applied to arbitrary numbers.
Hope this helps...
----
Yoshihiko Ichikawa, Dept of Info Sci, Fac of Sci, Ochanomizu University
Phone: +81-3-5978-5708 (Dial-in) / +81-3-5978-5704 (Library of Department)
Fax: +81-3-5978-5898 (Faculty) / +81-3-5878-5705 (Library of Department)
E-mail: [EMAIL PROTECTED]