Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Can't square zero as a complex number? (Scott N. Walck)
2. Re: Can't square zero as a complex number? (Carlos J. G. Duarte)
3. Re: Can't square zero as a complex number? (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 26 Jul 2012 12:08:00 -0400
From: "Scott N. Walck" <[email protected]>
Subject: [Haskell-beginners] Can't square zero as a complex number?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
Using GHC 7.4.1.
Thanks,
Scott
------------------------------
Message: 2
Date: Thu, 26 Jul 2012 17:27:04 +0100
From: "Carlos J. G. Duarte" <[email protected]>
Subject: Re: [Haskell-beginners] Can't square zero as a complex
number?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
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
------------------------------
Message: 3
Date: Thu, 26 Jul 2012 13:40:39 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Can't square zero as a complex
number?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
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
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 49, Issue 29
*****************************************