module Data.Number.Flint.NF.QQbar.Instances where

import System.IO.Unsafe
import Foreign.C.String
import Foreign.Marshal.Alloc ( free )

import Data.Number.Flint.NF.QQbar

instance Show QQbar where
  show :: QQbar -> String
show QQbar
x = IO String -> String
forall a. IO a -> a
unsafePerformIO (IO String -> String) -> IO String -> String
forall a b. (a -> b) -> a -> b
$ do
    (QQbar
_, CString
cs) <- QQbar -> (Ptr CQQbar -> IO CString) -> IO (QQbar, CString)
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
x Ptr CQQbar -> IO CString
qqbar_get_str
    String
s <- CString -> IO String
peekCString CString
cs
    CString -> IO ()
forall a. Ptr a -> IO ()
free CString
cs
    String -> IO String
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return String
s

instance Eq QQbar where
  == :: QQbar -> QQbar -> Bool
(==) QQbar
x QQbar
y = (QQbar, Bool) -> Bool
forall a b. (a, b) -> b
snd ((QQbar, Bool) -> Bool) -> (QQbar, Bool) -> Bool
forall a b. (a -> b) -> a -> b
$ (QQbar, (QQbar, Bool)) -> (QQbar, Bool)
forall a b. (a, b) -> b
snd ((QQbar, (QQbar, Bool)) -> (QQbar, Bool))
-> (QQbar, (QQbar, Bool)) -> (QQbar, Bool)
forall a b. (a -> b) -> a -> b
$ IO (QQbar, (QQbar, Bool)) -> (QQbar, (QQbar, Bool))
forall a. IO a -> a
unsafePerformIO (IO (QQbar, (QQbar, Bool)) -> (QQbar, (QQbar, Bool)))
-> IO (QQbar, (QQbar, Bool)) -> (QQbar, (QQbar, Bool))
forall a b. (a -> b) -> a -> b
$ 
    QQbar
-> (Ptr CQQbar -> IO (QQbar, Bool)) -> IO (QQbar, (QQbar, Bool))
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
x ((Ptr CQQbar -> IO (QQbar, Bool)) -> IO (QQbar, (QQbar, Bool)))
-> (Ptr CQQbar -> IO (QQbar, Bool)) -> IO (QQbar, (QQbar, Bool))
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
x ->
      QQbar -> (Ptr CQQbar -> IO Bool) -> IO (QQbar, Bool)
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
y ((Ptr CQQbar -> IO Bool) -> IO (QQbar, Bool))
-> (Ptr CQQbar -> IO Bool) -> IO (QQbar, Bool)
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
y -> do
        CInt
result <- Ptr CQQbar -> Ptr CQQbar -> IO CInt
qqbar_equal Ptr CQQbar
x Ptr CQQbar
y
        Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ CInt
result CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
1

instance Num QQbar where
  {-# INLINE (+) #-}
  + :: QQbar -> QQbar -> QQbar
(+) = (Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ())
-> QQbar -> QQbar -> QQbar
forall {a}.
(Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a)
-> QQbar -> QQbar -> QQbar
lift2 Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ()
qqbar_add
  {-# INLINE (-) #-}
  (-) = (Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ())
-> QQbar -> QQbar -> QQbar
forall {a}.
(Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a)
-> QQbar -> QQbar -> QQbar
lift2 Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ()
qqbar_sub
  {-# INLINE (*) #-}
  * :: QQbar -> QQbar -> QQbar
(*) = (Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ())
-> QQbar -> QQbar -> QQbar
forall {a}.
(Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a)
-> QQbar -> QQbar -> QQbar
lift2 Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO ()
qqbar_mul
  negate :: QQbar -> QQbar
negate = (Ptr CQQbar -> Ptr CQQbar -> IO ()) -> QQbar -> QQbar
forall {a}. (Ptr CQQbar -> Ptr CQQbar -> IO a) -> QQbar -> QQbar
lift1 Ptr CQQbar -> Ptr CQQbar -> IO ()
qqbar_neg
  abs :: QQbar -> QQbar
abs    = QQbar -> QQbar
forall a. HasCallStack => a
undefined
  fromInteger :: Integer -> QQbar
fromInteger Integer
x = IO QQbar -> QQbar
forall a. IO a -> a
unsafePerformIO (IO QQbar -> QQbar) -> IO QQbar -> QQbar
forall a b. (a -> b) -> a -> b
$ do
    QQbar
result <- IO QQbar
newQQbar
    QQbar -> (Ptr CQQbar -> IO ()) -> IO (QQbar, ())
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
result ((Ptr CQQbar -> IO ()) -> IO (QQbar, ()))
-> (Ptr CQQbar -> IO ()) -> IO (QQbar, ())
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
result -> do
      Ptr CQQbar -> CLong -> IO ()
qqbar_set_si Ptr CQQbar
result (Integer -> CLong
forall a. Num a => Integer -> a
fromInteger Integer
x)
    QQbar -> IO QQbar
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return QQbar
result
  signum :: QQbar -> QQbar
signum = QQbar -> QQbar
forall a. HasCallStack => a
undefined

lift1 :: (Ptr CQQbar -> Ptr CQQbar -> IO a) -> QQbar -> QQbar
lift1 Ptr CQQbar -> Ptr CQQbar -> IO a
f QQbar
x = (QQbar, (QQbar, a)) -> QQbar
forall a b. (a, b) -> a
fst ((QQbar, (QQbar, a)) -> QQbar) -> (QQbar, (QQbar, a)) -> QQbar
forall a b. (a -> b) -> a -> b
$ IO (QQbar, (QQbar, a)) -> (QQbar, (QQbar, a))
forall a. IO a -> a
unsafePerformIO (IO (QQbar, (QQbar, a)) -> (QQbar, (QQbar, a)))
-> IO (QQbar, (QQbar, a)) -> (QQbar, (QQbar, a))
forall a b. (a -> b) -> a -> b
$ 
  (Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a))
forall {a}. (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withNewQQbar ((Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a)))
-> (Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a))
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
result -> 
    QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
x ((Ptr CQQbar -> IO a) -> IO (QQbar, a))
-> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
x ->
      Ptr CQQbar -> Ptr CQQbar -> IO a
f Ptr CQQbar
result Ptr CQQbar
x
  
lift2 :: (Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a)
-> QQbar -> QQbar -> QQbar
lift2 Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a
f QQbar
x QQbar
y = (QQbar, (QQbar, (QQbar, a))) -> QQbar
forall a b. (a, b) -> a
fst ((QQbar, (QQbar, (QQbar, a))) -> QQbar)
-> (QQbar, (QQbar, (QQbar, a))) -> QQbar
forall a b. (a -> b) -> a -> b
$ IO (QQbar, (QQbar, (QQbar, a))) -> (QQbar, (QQbar, (QQbar, a)))
forall a. IO a -> a
unsafePerformIO (IO (QQbar, (QQbar, (QQbar, a))) -> (QQbar, (QQbar, (QQbar, a))))
-> IO (QQbar, (QQbar, (QQbar, a))) -> (QQbar, (QQbar, (QQbar, a)))
forall a b. (a -> b) -> a -> b
$ 
  (Ptr CQQbar -> IO (QQbar, (QQbar, a)))
-> IO (QQbar, (QQbar, (QQbar, a)))
forall {a}. (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withNewQQbar ((Ptr CQQbar -> IO (QQbar, (QQbar, a)))
 -> IO (QQbar, (QQbar, (QQbar, a))))
-> (Ptr CQQbar -> IO (QQbar, (QQbar, a)))
-> IO (QQbar, (QQbar, (QQbar, a)))
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
result ->
    QQbar -> (Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a))
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
x ((Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a)))
-> (Ptr CQQbar -> IO (QQbar, a)) -> IO (QQbar, (QQbar, a))
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
x ->
      QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
forall {a}. QQbar -> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
withQQbar QQbar
y ((Ptr CQQbar -> IO a) -> IO (QQbar, a))
-> (Ptr CQQbar -> IO a) -> IO (QQbar, a)
forall a b. (a -> b) -> a -> b
$ \Ptr CQQbar
y ->
        Ptr CQQbar -> Ptr CQQbar -> Ptr CQQbar -> IO a
f Ptr CQQbar
result Ptr CQQbar
x Ptr CQQbar
y