
#8539: Data.Complex shouldn't use default implementation of (**) -------------------------------------+------------------------------------- Reporter: jjaredsimpson | Owner: Type: bug | Status: patch Priority: low | Milestone: Component: Prelude | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by yalas): I think x raised to 0 must always be equal 1. Even for NaN: {{{ Prelude> (1/0*0) :: Double NaN Prelude> (1/0*0) ** 0 :: Double 1.0 }}} New complex power implementation: {{{ _ ** (0:+0) = 1 :+ 0 x ** (1:+0) = x (x:+0) ** (y:+0) | x >= 0 = (x ** y) :+ 0 x ** y = exp (log x * y) }}} But what about raising zero to complex power? Current implementation gets NaN: {{{ Prelude Data.Complex> exp $ log 0 * (1:+1) :: Complex Double NaN :+ NaN }}} Python throws an exception: {{{
0**(1+1j) Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: 0.0 to a negative or complex power }}} But wolphramalpha gets [https://www.wolframalpha.com/input/?i=0%5E%281%2B1i%29 0], [https://www.wolframalpha.com/input/?i=0%5E%28-1%2B1i%29 infinity] or [https://www.wolframalpha.com/input/?i=0%5E%281i%29 indeterminate].
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8539#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler