Haskell doesn't know much about infinity, but Haskell implementations are allowed to use IEEE floating point which has infinity.<br>And to get things right, there needs to be a few changes to the library to do the right thing for certain numbers, this is not news. In fact I filed a bug report a while back about it.
<br><br> -- Lennart<br><br><div><span class="gmail_quote">On 8/4/07, <b class="gmail_sendername">Andrew Coppin</b> <<a href="mailto:firstname.lastname@example.org">email@example.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Paul Johnson wrote:<br>> Andrew Coppin wrote:<br>>> > 0**2<br>>> 0<br>>><br>>> > (0 :+ 0)**2<br>>> NaN :+ NaN<br>>><br>>> (Is this a bug?)<br>> According to the Standard Prelude,
<br>> # x ** y = exp (log x * y)<br><br>I had a feeling this would be the cause.<br><br>> > log 0<br>> -Infinity<br><br>Oh. So... since when does Haskell know about infinity?<br><br>BTW, I recently had some code like this:
<br><br> foo x<br> | x < 0 = ...<br> | x == 0 = ...<br> | x > 0 = ...<br><br>I was most perplexed when I got a "non-exhaustive patterns" exception...<br>It turns out there was a NaN in there. I forget about that.
<br><br>> > exp (log 0 * 2)<br>> 0.0<br><br>Well that's interesting. I did wonder why it *doesn't* break in the real<br>case...<br><br>> On to the complex number case. From the standard for Complex:<br>
><br>> # log z = log (magnitude z) :+ phase z<br>><br>> # phase (0 :+ 0) = 0<br>> This is a special case for the phase of zero.<br>><br>> # (x:+y) * (x':+y') = (x*x'-y*y') :+ (x*y'+y*x')
<br>><br>> > log (0 :+ 0)<br>> (-Infinity) :+ 0.0<br>><br>> > log (0 :+ 0) * 2<br>> (-Infinity) :+ NaN<br>><br>> Which is the source of the problem. The imaginary part involves<br>> multiplying (-Infinity) by the
<br>> imaginary part of 2 (i.e. 0), which is NaN.<br><br>Um... why would infinity * 0 be NaN? That doesn't make sense...<br><br>> So no, its not a bug, its according to the standard.<br><br>So I'm the only person who was expecting zero squared to be zero? (IMHO
<br>the standard should try to implement mathematical operations in a<br>mathematically sensible way...)<br><br>> While working through this I also came across the following case which<br>> technically is a bug:<br>
><br>> > 0 ** 0<br>> 1.0<br>><br>> > exp (log 0 * 0)<br>> NaN<br>><br>> I suspect that GHCi is using a built-in exponentiation operator that<br>> doesn't quite conform to the standard in this case.
<br><br>Now that really *is* odd...<br><br>_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">