[Haskell-beginners] Can't square zero as a complex number?
Brent Yorgey
byorgey at seas.upenn.edu
Thu Jul 26 19:40:39 CEST 2012
On Thu, Jul 26, 2012 at 12:08:00PM -0400, Scott N. Walck wrote:
> Hi,
>
> Is there a reason why I can't use ** to square zero as a complex number?
>
> Prelude> :m Data.Complex
> Prelude Data.Complex> (0:+0) ** 2
> NaN :+ NaN
> Prelude Data.Complex> (0 :: Complex Double) ** 2
> NaN :+ NaN
It appears that Complex uses the default implementation of (**),
namely,
x ** y = exp (log x * y)
I have no opinions on whether this is a good idea. But as someone
else noted, (^) works fine if you know you want to use a positive
integral power.
-Brent
More information about the Beginners
mailing list