Don't use ^(2::Int) in Data.Complex.magnitude; partially fixes trac #2450
authorIan Lynagh <igloo@earth.li>
Sat, 4 Oct 2008 14:26:51 +0000 (14:26 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 4 Oct 2008 14:26:51 +0000 (14:26 +0000)
We still might want to make a RULE for this, so the bug is not fully fixed.

Data/Complex.hs

index 3acfa03..60ee834 100644 (file)
@@ -103,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.