{-# OPTIONS_GHC -Wno-orphans #-}
module AERN2.Complex
(
CComplex, ccomplex, HasCComplex, CanBeCComplex,
)
where
import MixedTypesNumPrelude
import Data.Complex
import AERN2.Real
type CComplex = Complex CReal
type CanBeCComplex t = ConvertibleExactly t CComplex
type HasCComplex t = ConvertibleExactly CComplex t
ccomplex :: (CanBeCComplex t) => t -> CComplex
ccomplex :: t -> CComplex
ccomplex = t -> CComplex
forall t1 t2. ConvertibleExactly t1 t2 => t1 -> t2
convertExactly
instance (HasCReals t, HasIntegers t) => (ConvertibleExactly CReal (Complex t))
where
safeConvertExactly :: CReal -> ConvertResult (Complex t)
safeConvertExactly CReal
n =
do
t
nT <- CReal -> ConvertResult t
forall t1 t2. ConvertibleExactly t1 t2 => t1 -> ConvertResult t2
safeConvertExactly CReal
n
t
zT <- Integer -> ConvertResult t
forall t1 t2. ConvertibleExactly t1 t2 => t1 -> ConvertResult t2
safeConvertExactly Integer
0
Complex t -> ConvertResult (Complex t)
forall (m :: * -> *) a. Monad m => a -> m a
return (Complex t -> ConvertResult (Complex t))
-> Complex t -> ConvertResult (Complex t)
forall a b. (a -> b) -> a -> b
$ t
nT t -> t -> Complex t
forall a. a -> a -> Complex a
:+ t
zT
_test1 :: CComplex
_test1 :: CComplex
_test1 = Rational -> CComplex
forall t. CanBeCComplex t => t -> CComplex
ccomplex Rational
1.0
_test2 :: CComplex
_test2 :: CComplex
_test2 = CReal -> CComplex
forall t. CanBeCComplex t => t -> CComplex
ccomplex (CReal -> CComplex) -> CReal -> CComplex
forall a b. (a -> b) -> a -> b
$ Integer -> CReal
forall t. CanBeCReal t => t -> CReal
creal Integer
1