{-|
    Module      :  Numeric.CatchingExceptions.MixedTypes.Elementary
    Description :  CatchingExceptions elementary operations
    Copyright   :  (c) Michal Konecny
    License     :  BSD3

    Maintainer  :  mikkonecny@gmail.com
    Stability   :  experimental
    Portability :  portable

    Elementary operations instances.  See parent module for more information.
-}
module Numeric.CatchingExceptions.MixedTypes.Elementary
(
)
where

import Numeric.MixedTypes
-- import qualified Prelude as P
-- import Text.Printf

-- import qualified Data.Set as Set

import Numeric.CatchingExceptions.Type
import Numeric.CatchingExceptions.Lifts
-- import Numeric.CatchingExceptions.MixedTypes.Conversions ()
import Numeric.CatchingExceptions.MixedTypes.Comparisons ()
import Numeric.CatchingExceptions.MixedTypes.Ring ()
import Numeric.CatchingExceptions.MixedTypes.Power
-- import Numeric.CatchingExceptions.MixedTypes.Field ()

instance
  (CanSqrt t1, CanTestPosNeg t1,
  CanTestValid (SqrtType t1), Show (SqrtType t1))
  =>
  CanSqrt (CatchingNumExceptions t1)
  where
  type SqrtType (CatchingNumExceptions t1) = CatchingNumExceptions (SqrtType t1)
  sqrt = liftCtoCwithTest (testNonNegative (OutOfRange "sqrt(x) with x < 0")) sqrt

instance
  (CanExp t1,
  CanTestValid (ExpType t1), Show (ExpType t1))
  =>
  CanExp (CatchingNumExceptions t1)
  where
  type ExpType (CatchingNumExceptions t1) = CatchingNumExceptions (ExpType t1)
  exp = liftCtoC exp

instance
  (CanLog t1, CanTestPosNeg t1,
  CanTestValid (LogType t1), Show (LogType t1))
  =>
  CanLog (CatchingNumExceptions t1)
  where
  type LogType (CatchingNumExceptions t1) = CatchingNumExceptions (LogType t1)
  log = liftCtoCwithTest (testPositive (OutOfRange "log(x) with x <= 0")) log

instance
  (CanSinCos t1,
  CanTestValid (SinCosType t1), Show (SinCosType t1))
  =>
  CanSinCos (CatchingNumExceptions t1)
  where
  type SinCosType (CatchingNumExceptions t1) = CatchingNumExceptions (SinCosType t1)
  cos = liftCtoC cos
  sin = liftCtoC sin
