Commit d14821d2 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-09-19 14:05:01 by simonmar]

Add some specialisations for Complex Double.

(are SPECIALISE instance pragmas now ignored?)
parent dd7ecb76
% -----------------------------------------------------------------------------
% $Id: Complex.lhs,v 1.5 2000/06/30 13:39:35 simonmar Exp $
% $Id: Complex.lhs,v 1.6 2001/09/19 14:05:01 simonmar Exp $
%
% (c) The University of Glasgow, 1994-2000
%
......@@ -55,28 +55,36 @@ data (RealFloat a) => Complex a = !a :+ !a deriving (Eq, Read, Show)
%*********************************************************
\begin{code}
{-# SPECIALISE realPart :: Complex Double -> Double #-}
{-# SPECIALISE imagPart :: Complex Double -> Double #-}
realPart, imagPart :: (RealFloat a) => Complex a -> a
realPart (x :+ _) = x
imagPart (_ :+ y) = y
{-# SPECIALISE conjugate :: Complex Double -> Complex Double #-}
conjugate :: (RealFloat a) => Complex a -> Complex a
conjugate (x:+y) = x :+ (-y)
{-# SPECIALISE mkPolar :: Double -> Double -> Complex Double #-}
mkPolar :: (RealFloat a) => a -> a -> Complex a
mkPolar r theta = r * cos theta :+ r * sin theta
{-# SPECIALISE cis :: Double -> Complex Double #-}
cis :: (RealFloat a) => a -> Complex a
cis theta = cos theta :+ sin theta
{-# SPECIALISE polar :: Complex Double -> (Double,Double) #-}
polar :: (RealFloat a) => Complex a -> (a,a)
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)))
where k = max (exponent x) (exponent y)
mk = - k
{-# SPECIALISE phase :: Complex Double -> Double #-}
phase :: (RealFloat a) => Complex a -> a
phase (0 :+ 0) = 0 -- SLPJ July 97 from John Peterson
phase (x:+y) = atan2 y x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment