[Haskell-beginners] Can't square zero as a complex number?

Carlos J. G. Duarte carlos.j.g.duarte at gmail.com
Thu Jul 26 18:27:04 CEST 2012


On 07/26/12 17:08, 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
>
>

I think that's because (**) allows foating exponents which can't be 
deterministically applied to a complex base (if I have my maths correct, 
that is).
You can use the (^) which can be applied to any numeric base, but only 
allows integral exponents.

Prelude Data.Complex> (0 :: Complex Double) ^ 2
0.0 :+ 0.0




More information about the Beginners mailing list