[project @ 2004-03-27 14:15:24 by panne]
[ghc-base.git] / Data / Complex.hs
index e132f21..621b48e 100644 (file)
@@ -1,15 +1,13 @@
 -----------------------------------------------------------------------------
--- 
+-- |
 -- Module      :  Data.Complex
 -- Copyright   :  (c) The University of Glasgow 2001
--- License     :  BSD-style (see the file libraries/core/LICENSE)
+-- License     :  BSD-style (see the file libraries/base/LICENSE)
 -- 
 -- Maintainer  :  libraries@haskell.org
 -- Stability   :  provisional
 -- Portability :  portable
 --
--- $Id: Complex.hs,v 1.1 2001/06/28 14:15:02 simonmar Exp $
---
 -- Complex numbers.
 --
 -----------------------------------------------------------------------------
@@ -41,7 +39,13 @@ module Data.Complex
 
 import Prelude
 
-import Data.Dynamic
+#ifndef __NHC__
+import Data.Typeable
+#endif
+
+#ifdef __HUGS__
+import Hugs.Prelude(Num(fromInt), Fractional(fromDouble))
+#endif
 
 infix  6  :+
 
@@ -58,24 +62,30 @@ 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
@@ -84,8 +94,10 @@ phase (x:+y)  = atan2 y x
 -- -----------------------------------------------------------------------------
 -- Instances of Complex
 
-#include "Dynamic.h"
+#ifndef __NHC__
+#include "Typeable.h"
 INSTANCE_TYPEABLE1(Complex,complexTc,"Complex")
+#endif
 
 instance  (RealFloat a) => Num (Complex a)  where
     {-# SPECIALISE instance Num (Complex Float) #-}
@@ -98,6 +110,9 @@ instance  (RealFloat a) => Num (Complex a)  where
     signum 0           =  0
     signum z@(x:+y)    =  x/r :+ y/r  where r = magnitude z
     fromInteger n      =  fromInteger n :+ 0
+#ifdef __HUGS__
+    fromInt n          =  fromInt n :+ 0
+#endif
 
 instance  (RealFloat a) => Fractional (Complex a)  where
     {-# SPECIALISE instance Fractional (Complex Float) #-}
@@ -109,6 +124,9 @@ instance  (RealFloat a) => Fractional (Complex a)  where
                                 d   = x'*x'' + y'*y''
 
     fromRational a     =  fromRational a :+ 0
+#ifdef __HUGS__
+    fromDouble a       =  fromDouble a :+ 0
+#endif
 
 instance  (RealFloat a) => Floating (Complex a)        where
     {-# SPECIALISE instance Floating (Complex Float) #-}