```-- | Complex numbers

module Feldspar.Core.Functions.Complex where

import Data.Complex (Complex (..))
import qualified Data.Complex as C

import Feldspar.Core.Types
import Feldspar.Core.Representation
import Feldspar.Core.Constructs
import Feldspar.Core.Functions.Num

complex :: (Numeric a, RealFloat a) => Data a -> Data a -> Data (Complex a)
complex = function2 "complex" fullProp (:+)

realPart :: (Numeric a, RealFloat a) => Data (Complex a) -> Data a
realPart = function1 "creal" fullProp C.realPart

imagPart :: (Numeric a, RealFloat a) => Data (Complex a) -> Data a
imagPart = function1 "cimag" fullProp C.imagPart

conjugate :: (Numeric a, RealFloat a) => Data (Complex a) -> Data (Complex a)
conjugate = function1 "conjugate" fullProp C.conjugate

mkPolar :: (Numeric a, RealFloat a) => Data a -> Data a -> Data (Complex a)
mkPolar = function2 "mkPolar" fullProp C.mkPolar

cis :: (Numeric a, RealFloat a) => Data a -> Data (Complex a)
cis = function1 "cis" fullProp C.cis

magnitude :: (Numeric a, RealFloat a) => Data (Complex a) -> Data a
magnitude = function1 "magnitude" fullProp C.magnitude

phase :: (Numeric a, RealFloat a) => Data (Complex a) -> Data a
phase = function1 "phase" fullProp C.phase

polar :: (Numeric a, RealFloat a) => Data (Complex a) -> (Data a, Data a)
polar c = (magnitude c, phase c)

infixl 6 +.

(+.) :: (Numeric a, RealFloat a) => Data a -> Data a -> Data (Complex a)
(+.) = complex

iunit :: (Numeric a, RealFloat a) => Data (Complex a)
iunit = 0 +. 1

```