[commit: ghc] master: base: Fix (**) instance for Data.Complex (#8539) (1f6b1ab)

git at git.haskell.org git at git.haskell.org
Tue Nov 18 18:21:45 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/1f6b1ab4b6d7203481bfaf374b014972f7756fb2/ghc

>---------------------------------------------------------------

commit 1f6b1ab4b6d7203481bfaf374b014972f7756fb2
Author: Austin Seipp <austin at well-typed.com>
Date:   Tue Nov 18 12:10:34 2014 -0600

    base: Fix (**) instance for Data.Complex (#8539)
    
    Reviewed-by: Edward Kmett <ekmett at gmail.com>
    Authored-by: Yalas, Scott Turner
    
    Signed-off-by: Austin Seipp <austin at well-typed.com>


>---------------------------------------------------------------

1f6b1ab4b6d7203481bfaf374b014972f7756fb2
 libraries/base/Data/Complex.hs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libraries/base/Data/Complex.hs b/libraries/base/Data/Complex.hs
index 2baa60b..756ea67 100644
--- a/libraries/base/Data/Complex.hs
+++ b/libraries/base/Data/Complex.hs
@@ -138,6 +138,22 @@ instance  (RealFloat a) => Floating (Complex a) where
                       where expx = exp x
     log z          =  log (magnitude z) :+ phase z
 
+    x ** y = case (x,y) of
+      (_ , (0:+0))   ->  1 :+ 0
+      ((0:+0), (re:+_))
+        | re > 0     ->  0 :+ 0
+        | re < 0     ->  inf :+ 0
+        | otherwise  ->  nan :+ nan
+      ((re:+im), y)
+        | (isInfinite re || isInfinite im) -> case y of
+          (exp_re:+_) | exp_re > 0  -> inf :+ 0
+                      | exp_re < 0  -> 0 :+ 0
+                      | otherwise   -> nan :+ nan
+      (x, y)         ->  exp (log x * y)
+      where
+        inf = 1/0
+        nan = 0/0
+
     sqrt (0:+0)    =  0
     sqrt z@(x:+y)  =  u :+ (if y < 0 then -v else v)
                       where (u,v) = if x < 0 then (v',u') else (u',v')



More information about the ghc-commits mailing list