Don't use ^(2::Int) in Data.Complex.magnitude; partially fixes trac #2450
[ghc-base.git] / Data / Complex.hs
index 7d29e77..60ee834 100644 (file)
@@ -44,9 +44,6 @@ module Data.Complex
 import Prelude
 
 import Data.Typeable
-#ifdef __GLASGOW_HASKELL__
-import Data.Generics.Basics( Data )
-#endif
 
 #ifdef __HUGS__
 import Hugs.Prelude(Num(fromInt), Fractional(fromDouble))
@@ -65,11 +62,7 @@ infix  6  :+
 data (RealFloat a) => Complex a
   = !a :+ !a    -- ^ forms a complex number from its real and imaginary
                 -- rectangular components.
-# if __GLASGOW_HASKELL__
-        deriving (Eq, Show, Read, Data)
-# else
         deriving (Eq, Show, Read)
-# endif
 
 -- -----------------------------------------------------------------------------
 -- Functions over Complex
@@ -110,9 +103,10 @@ polar z          =  (magnitude z, phase z)
 {-# SPECIALISE magnitude :: Complex Double -> Double #-}
 magnitude :: (RealFloat a) => Complex a -> a
 magnitude (x:+y) =  scaleFloat k
-                     (sqrt ((scaleFloat mk x)^(2::Int) + (scaleFloat mk y)^(2::Int)))
+                     (sqrt (sqr (scaleFloat mk x) + sqr (scaleFloat mk y)))
                     where k  = max (exponent x) (exponent y)
                           mk = - k
+                          sqr z = z * z
 
 -- | The phase of a complex number, in the range @(-'pi', 'pi']@.
 -- If the magnitude is zero, then so is the phase.