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

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

    Field operations instances.  See parent module for more information.
-}
module Numeric.CatchingExceptions.MixedTypes.Field
(
)
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


instance
  (CanDiv t1 t2, CanTestZero t2,
  CanTestValid (DivType t1 t2), Show (DivType t1 t2))
  =>
  CanDiv (CatchingNumExceptions t1) (CatchingNumExceptions t2)
  where
  type DivType (CatchingNumExceptions t1) (CatchingNumExceptions t2) = CatchingNumExceptions (DivType t1 t2)
  divide = liftCCtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv Integer t2, CanTestZero t2,
  CanTestValid (DivType Integer t2), Show (DivType Integer t2))
  =>
  CanDiv Integer (CatchingNumExceptions t2)
  where
  type DivType Integer (CatchingNumExceptions t2) = CatchingNumExceptions (DivType Integer t2)
  divide = liftOCtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv t1 Integer,
  CanTestValid (DivType t1 Integer), Show (DivType t1 Integer))
  =>
  CanDiv (CatchingNumExceptions t1) Integer
  where
  type DivType (CatchingNumExceptions t1) Integer = CatchingNumExceptions (DivType t1 Integer)
  divide = liftCOtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv Int t2, CanTestZero t2,
  CanTestValid (DivType Int t2), Show (DivType Int t2))
  =>
  CanDiv Int (CatchingNumExceptions t2)
  where
  type DivType Int (CatchingNumExceptions t2) = CatchingNumExceptions (DivType Int t2)
  divide = liftOCtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv t1 Int,
  CanTestValid (DivType t1 Int), Show (DivType t1 Int))
  =>
  CanDiv (CatchingNumExceptions t1) Int
  where
  type DivType (CatchingNumExceptions t1) Int = CatchingNumExceptions (DivType t1 Int)
  divide = liftCOtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv Rational t2, CanTestZero t2,
  CanTestValid (DivType Rational t2), Show (DivType Rational t2))
  =>
  CanDiv Rational (CatchingNumExceptions t2)
  where
  type DivType Rational (CatchingNumExceptions t2) = CatchingNumExceptions (DivType Rational t2)
  divide = liftOCtoCwithTest (\_a b -> testNonZero DivByZero b) divide

instance
  (CanDiv t1 Rational,
  CanTestValid (DivType t1 Rational), Show (DivType t1 Rational))
  =>
  CanDiv (CatchingNumExceptions t1) Rational
  where
  type DivType (CatchingNumExceptions t1) Rational = CatchingNumExceptions (DivType t1 Rational)
  divide = liftCOtoCwithTest (\_a b -> testNonZero DivByZero b) divide


{- TODO sqrt, sine, cosine, etc -}
